You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by ibrahim <ib...@natlab.research.philips.com> on 2001/02/14 10:08:11 UTC
trouble with getGrammarDocument()
Hi all,
I tried this code below to get the SchemaGrammar document. Somehow it keeps on
returning null. Can't figure out what's going wrong there.
could you plz reply asap since I need it urgently ?
thx a a lot,
cath
XML FILE:
<?xml version="1.0" encoding="UTF-8"?>
<dv:main
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:dv="http://at.com/SXE"
xsi:schemaLocation="http://at.com/SXE TNS.xsd">
<dv:child />
</dv:main>
XSD FILE:
<?xml version="1.0" encoding="UTF-8"?>
<schema
xmlns="http://www.w3.org/1999/XMLSchema"
xmlns:dv="http://at.com/SXE"
targetNamespace="http://at.com/SXE"
elementFormDefault="qualified">
<element name="main" >
<complexType content="elementOnly">
<element name="child" type="dv:child" minOccurs="0" maxOccurs="unbounded" />
</complexType>
</element>
<complexType name="child" content="empty" />
</schema>
PARSER JAVA CODE:
class Parser extends DOMParser{
public XMLValidator getValidator(){
return fValidator;
}
}
public class EdParser {
public static void main(String[] args){
EdParser ep = new EdParser();
ep.parsing ("TNS.xml", true);
}
public Document parsing( String xmlFilename, boolean valid ) {
if (xmlFilename.length()==0) return null;
Parser parser = new Parser();
XMLValidator validator = parser.getValidator();
GrammarResolver gr = new GrammarResolverImpl();
validator.setGrammarResolver(gr);
try {
parser.setFeature("http://xml.org/sax/features/validation", valid );
parser.parse(xmlFilename);
}
catch(Exception e) { e.printStackTrace(); }
String namespaceKey="http://at.com/SXE";
Grammar g = gr.getGrammar(namespaceKey);
System.out.println("Grammar : " + g);
System.out.println("Grammar: " + g.getGrammarDocument()); //this one gives null
return null;
}