Hi. The following works for me with Xerces 2.0.1. You can use
that as a template and add features until you find something
that doesn't work.
public static Document validateByXSD(String fileURI)
throws Exception {
String[] features = new String[] {
"http://xml.org/sax/features/validation",
"http://apache.org/xml/features/validation/schema"
};
FileInputStream fis = new FileInputStream(fileURI);
InputSource source = new InputSource(fis);
DOMParser parser = new DOMParser();
parser.setErrorHandler(new ErrorSink());
for(int i=0; i<features.length; i++) {
parser.setFeature(features[i], true);
}
parser.parse(source);
return parser.getDocument();
}
ErrorSink.java:
import org.xml.sax.*;
/**
* Trivial output sink to dump error messages.
*/
public class ErrorSink implements ErrorHandler {
public void warning(SAXParseException e) throws SAXException {
System.out.println(">> Warning: "+e);
}
public void error(SAXParseException e) throws SAXException {
System.out.println(">> Error: "+e);
}
public void fatalError(SAXParseException e) throws SAXException {
System.out.println(">> Fatal Error: "+e);
}
}
BR,
Morten
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]