Min Lee wrote:
>
> Sorry for the repeated emails ;} The problem seems to be in
> org.xml.sax.helpers.XMLReaderAdapter.setupXMLReader(). It always sets
> "http://xml.org/sax/features/namespaces" feature to "false" for some reason
> :-/
Let me restate the problem: you want to validate an XML document using
XML Schema using JAXP.
In your code, you have:
> >sp.parse(new InputSource(args[0]),
> > new HandlerBase() {
> > public void error(SAXParseException e) {
> > System.out.println("Error: " + e.getMessage());
> > }
> > public void fatalError(SAXParseException e) {
> > System.out.println("Fatal Error: " + e.getMessage());
> > }
> > public void warning(SAXParseException e) {
> > System.out.println("Warning: " + e.getMessage());
> > }
> > }
> > );
Note that you are using HandlerBase which is part of SAX 1.0 which does
not have support for Namespaces. This causes the parser to use an
XMLReaderAdapter to make a SAX 2 parser look like a SAX 1.0 parser which
does _not_ support namespaces. I wrote in an earlier post the
following:
So to summarize, I think what is going on here is that even though the
XSD file does not use a targetNamespace, the instance document must use
namespaces to point to the XSD file so the parser still needs to have
namespaces turned on. Hopefully someone will correct me if I am wrong.
If instead you used DefaultHandler from SAX 2, then the program should
work.
In any case, what I prefer to do is to stick with the standard SAX 2.0
APIs and just use JAXP to instantiate the platform dependent parser.
That way there is less API to learn. JAXP is used for the parts that
are not covered by SAX 2.0. Something like:
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setValidating(true); // Also could instead use hard to remember
// SAX feature string later
SAXParser sp = spf.newSAXParser();
XMLReader xmlReader = sp.getXMLReader();
xmlReader.setErrorHandler(...);
xmlReader.setContentHandler(...);
xmlReader.parse(new InputSource(...));
-Edwin
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]