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

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 UTC