My input is a well-formed XML document and the corresponding XML Schema document. What I would like to do is determine the location in the XML document, which causes it to refuse to validate against the XML Schema document. I could not figure out how to do this using the standard validation method in Java:
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(... );
Validator validator = schema.newValidator();
DocumentBuilderFactory ...
DocumentBuilder ...
Document document = DocumentBuilder.parse(... );
try {
validator.validate(new DOMSource(document));
...
} catch (SAXParseException e) {
...
}
I played with the idea of getting at least the row and column number from SAXParseException, but they are always set to -1, -1 with a validation error.
source
share