views:

486

answers:

5

When I want to validate my XML docuemnts against a schema in my server-side Java, I use the built-in JRE Xerces implementation and javax.xml.validation.Schema. It works fine, but when validation fails, Xerces gives error messages that are very close to useless, for example:

cvc-minLength-valid: Value '' with length = '0' is not facet-valid with respect to minLength '1' for type 'PopulatedStringType'

These can take an age to diagnose and track down to the particular part of the XML document that fails validation, and all because of a poor error message.

So my question is, do you use an alternative means of validating XML against Schema, that gives a more useful output on validation failure?

Please not that this is server-side Java, so please don't say "use XML Spy" or similar.

A: 

We use Oracle's XDK (XML Development Kit) which includes xmlparserv2.jar with a validating parser and XSLT 2.0. It uses the JAXB API so you should only have to add it to your classpath and change your imports. It throws errors that aren't perfect, but I would say more easily understood than your example.

dacracot
A: 

xmlstarlet(xmlstar.sourceforge.net/) is a command line toolkit. you could run it using Runtime.exec() for a given xml (as long as the xml is in a file).

anjanb
A: 

We use castor (www.castor.org).

Paul Croarkin
Why do you use Castor, and how does it help my problem?
skaffman
+1  A: 

In your handler for the validation, you should receive a SAXParseException with that message, as well as the column number and the line number in the XML file. Isnt't it the case?

Damien B
A: 
Mads Hansen