  | |  | XMLGrammarBuilder sample | XMLGrammarBuilder sample 2004-03-04 - By Wax, Ed
I'm having trouble with one of the sample programs that comes with he xerces-j 2.6.2 distribution. It is: ~xerces/samples/xni/XMLGrammarBuilder.java
As distributed, it will preparse multiple XSD files (grammars). I have an XSD file with an intentional bug. If I specify that XSD file as the first one to preparse, the error will be reported. However, if I specify a valid XSD file first and then the one with the bug, the error will not be reported. Is there a method to "reset" things?
Here's the block of code that preparses the specified grammars (XSD files):
... // parse the grammar... try { if (isDTD) { for (i = 0; i < externalDTDs.size(); i++) { Grammar g = preparser.preparseGrammar( XMLGrammarDescription.XML_DTD, stringToXIS((String)externalDTDs.elementAt(i))); // we don't really care about g; grammarPool will take care of everything. } } else { // must be schemas! for (i = 0; i < schemas.size(); i++) { Grammar g = preparser.preparseGrammar( XMLGrammarDescription.XML_SCHEMA, stringToXIS((String)schemas.elementAt(i))); // we don't really care about g; grammarPool will take care of everything. } } } catch (Exception e) { e.printStackTrace(); System.exit(1); } ...
Regards, Ed
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <META NAME="Generator" CONTENT="MS Exchange Server version 6.0.6249.1"> <TITLE>XMLGrammarBuilder sample</TITLE> </HEAD> <BODY> <!-- Converted from text/rtf format -->
<P><FONT SIZE=2 FACE="Tahoma">I'm having trouble with one of the sample programs that comes with he xerces-j 2.6.2 distribution. It is:</FONT>
<BR><FONT SIZE=2 FACE="Tahoma">~xerces/samples/xni/XMLGrammarBuilder.java</FONT> </P>
<P><FONT SIZE=2 FACE="Tahoma">As distributed, it will preparse multiple XSD files (grammars). I have an XSD file with an intentional bug. If I specify that XSD file as the first one to preparse, the error will be reported. However, if I specify a valid XSD file first and then the one with the bug, the error will not be reported. Is there a method to "reset " things?</FONT></P>
<P><FONT SIZE=2 FACE="Tahoma">Here's the block of code that preparses the specified grammars (XSD files):</FONT> </P> <UL> <P><FONT SIZE=2 FACE="Courier New">...</FONT>
<BR><FONT SIZE=2 FACE="Courier New">// parse the grammar...</FONT>
<BR><B><FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">try</FONT></B><FONT SIZE =2 FACE="Courier New"> {</FONT>
<BR> <B> <FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">if</FONT></B><FONT SIZE=2 FACE="Courier New"> (isDTD) {< /FONT>
<BR> <B> <FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">for</FONT></B> <FONT SIZE=2 FACE="Courier New"> (i = 0; i < externalDTDs.size(); i++) {< /FONT>
<BR> <FONT SIZE=2 FACE= "Courier New">Grammar g = preparser.preparseGrammar(</FONT>
<BR> <FONT SIZE=2 FACE="Courier New">XMLGrammarDescription.XML_DTD , </FONT>
<BR> <FONT SIZE=2 FACE="Courier New">stringToXIS((String )externalDTDs.elementAt(i)));</FONT>
<BR> <FONT COLOR="#3F7F5F" SIZE=2 FACE="Courier New">// we don't really care about g; grammarPool will take care of everything.</FONT>
<BR> <FONT SIZE=2 FACE="Courier New">}</FONT>
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">}</FONT><FONT SIZE=2 FACE="Courier New"></FONT><B> <FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">else</FONT></B><FONT SIZE=2 FACE= "Courier New"> </FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">{</FONT> <FONT SIZE=2 FACE="Courier New"> </FONT><FONT COLOR="#3F7F5F" SIZE=2 FACE= "Courier New">// must be schemas!</FONT>
<BR><B>   ; <FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">for</FONT></B> <FONT SIZE=2 FACE="Courier New"> </FONT><FONT COLOR="#000000" SIZE=2 FACE= "Courier New">(i</FONT><FONT SIZE=2 FACE="Courier New"> </FONT><FONT COLOR=" #000000" SIZE=2 FACE="Courier New">=</FONT><FONT SIZE=2 FACE="Courier New"> < /FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">0;</FONT><FONT SIZE=2 FACE ="Courier New"> </FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">i</FONT> <FONT SIZE=2 FACE="Courier New"> </FONT><FONT COLOR="#000000" SIZE=2 FACE= "Courier New"><</FONT><FONT SIZE=2 FACE="Courier New"> </FONT><FONT COLOR=" #000000" SIZE=2 FACE="Courier New">schemas.size();</FONT><FONT SIZE=2 FACE= "Courier New"> </FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">i++)</FONT ><FONT SIZE=2 FACE="Courier New"> </FONT><FONT COLOR="#000000" SIZE=2 FACE= "Courier New">{</FONT>
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">Grammar</FONT><FONT SIZE=2 FACE="Courier New"> </FONT ><FONT COLOR="#000000" SIZE=2 FACE="Courier New">g</FONT><FONT SIZE=2 FACE= "Courier New"> </FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">=</FONT> <FONT SIZE=2 FACE="Courier New"> </FONT><FONT COLOR="#000000" SIZE=2 FACE= "Courier New">preparser.preparseGrammar(</FONT>
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New" >XMLGrammarDescription.XML_SCHEMA,</FONT><FONT SIZE=2 FACE="Courier New"> </FONT >
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">stringToXIS( (String)schemas.elementAt(i)));</FONT>
<BR> <FONT COLOR="#3F7F5F" SIZE=2 FACE="Courier New">// we don't really care about g; grammarPool will take care of everything.</FONT>
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">}</FONT>
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">}</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">} catch (Exception e) {< /FONT>
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">e.printStackTrace();</FONT>
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">System.exit(1);</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">}</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">...</FONT> </P> </UL> <P><FONT COLOR="#000000" SIZE=2 FACE="Tahoma">Regards,</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Tahoma">Ed</FONT> </P>
</BODY> </HTML>
|
|
 |