tags:

views:

41

answers:

2

I am using javax.xml.validation.Validator from SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) to perform XSD validation.

I would like to be able to get a better error message back for validation errors. All I currently get is: org.xml.sax.SAXParseException: cvc-minLength-valid: Value '' with length = '0' is not facet-valid with respect to minLength '1' for type 'TypeCode'.

Is it possible to have the error print out which element or xml fragment is failing validation?

*Edit: I am using the standard java6 xml parsers *Edit2: Sorry for not mentioning - I am using JAXB to read the XML with a contenthandler and a listener (due to the XML being > 1GB most of the time).

A: 
StaxMan
All I get is an error message similar to what I provided above with no clue to which element has the problem. :-(
Steven
With MSV? Do you at least get location information, or not even that?
StaxMan
No location at all. Just what is shown above.
Steven
A: 

Have you tried registering an ErrorHandler with your Validator and accessing the details on the corresponding SAXParseException?

Blaise Doughan
Right, you can use Document.normalizeDocument() after setting an error handler, and get pointers to the elements with errors. The only problem with this solution is that normalizeDocument() will change your DOM document. You could clone it before, but then you have to find a way to link cloned elements.
Damien