W3C home > Mailing lists > Public > www-xml-schema-comments@w3.org > October to December 2002

Re: Validating xml using a schema with domparser does not work

From: by way of <lane@mcs.anl.gov>
Date: Thu, 03 Oct 2002 06:23:45 -0600
Message-Id: <5.1.0.14.1.20021003062341.01ba1cf0@localhost>
To: W3C XML Schema Comments list <www-xml-schema-comments@w3.org>




Jimmy,

I was having this same problem and eventually figured something out that 
works.  I think what's going on is that validation *is* happening when the 
schema is found, but the errors are not being propegated to the program 
using the parser.  The way I solved this was to use the parser's 
setErrorHandler() method, and pass an intance of the ErrorHandler interface 
which relays the errors to my code:

DOMParser xmlParser = new DOMParser();
xmlParser.setFeature("http://xml.org/sax/features/validation", true);
xmlParser.setErrorHandler(new MyErrorHandler());

...

public class MyErrorHandler implements ErrorHandler {
...
   public void error(SAXParserException saxpe) {
      System.error.println(saxpe.getMessage()); //or whatever
   }
...
}

This seems kind of silly, IMHO, but it works for me.


Peter
Received on Thursday, 3 October 2002 08:35:27 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Sunday, 6 December 2009 18:13:01 GMT