Hi Cath,
It looks to me (on a very brief and superficial examination) like the
fDocument field of the Grammar object isn't set when an instance document
is being validated against a schema (Andy, Jeff, please correct me if I'm
wrong...) The reason for this isn't totally obvious to me; I can't see how
it would hurt to make this available, but I'd definitely have to do some
more checking before making this change. I would point out, though, that
you're perfectly free to read the schema document into a DOM tree yourself;
you'll get no less information this way. Even if the fDocument field did
have useful data it still wouldn't help you access Xerces representation of
the grammar.
But as to your problem: Your best bet is to look through the code of
XMLValidator to see how an instance document is validated against an
already-existing grammar. If you simply compare your document's DOM tree
against the raw DOM representation of a schema, then you have to do all the
work the parser does to extract the information within the schema. Using
the XMLValidator methods won't be an easy task either, but at least you'll
have a processed grammar to work with.
Keep me informed on how your project goes. You've picked a very tough
problem to work on and if you solve it you'll have made a real
contribution!
Best of luck,
Neil
Neil Graham
XML Parser Development
IBM Toronto Lab
Phone: 416-448-3519, T/L 778-3519
E-mail: [EMAIL PROTECTED]
ibrahim <[EMAIL PROTECTED]> on 02/14/2001 04:08:11 AM
Please respond to [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
cc:
Subject: 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;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]