skaffman
skaffman

Reputation: 403441

What do you use for validation against XML schema?

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.

Upvotes: 2

Views: 1508

Answers (5)

Mads Hansen
Mads Hansen

Reputation: 66714

If you are having trouble interpreting the Xerces errors and would like something that helps to highlight where in your document you have violated the rules, check out some of the XML authoring tools such as oXygen.

alt text
(source: oxygenxml.com)

Once you associate the schema with your instance XML document the editor will highlight the offending area of the document and provide you with a description of the violation.

Plus, you can use different engines to perform the validation:

oXygen has built-in support for: Xerces, LIBXML, XSV, Saxon SA, MSXML4.0, MSXML .NET and SQC.

Upvotes: 0

Paul Croarkin
Paul Croarkin

Reputation: 14675

We use Castor.

Castor is an Open Source data binding framework for Java[tm]. It's the shortest path between Java objects, XML documents and relational tables. Castor provides Java-to-XML binding, Java-to-SQL persistence, and more.

Upvotes: 0

Damien B
Damien B

Reputation: 2003

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?

Upvotes: 2

anjanb
anjanb

Reputation: 13847

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).

Upvotes: 0

dacracot
dacracot

Reputation: 22338

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.

Upvotes: 0

Related Questions