users@jaxb.java.net

Validation error reporting limitiations

From: Marcus Walls <marcus.walls_at_aspective.com>
Date: Fri, 06 Jun 2003 12:50:11 +0100

I am using JAXB in an XML-aware application. Users are permitted to submit
XML documents for processing, and thus when things go wrong it is
acceptable (and a requirement for me) to display XML-specific error
messages. I acknowledge that this won't be the case for every JAXB
application and indeed I appreciate that it will not be appropriate to refer
to elements, schemas and even lines numbers in some application error
messages.

Because my application is XML-aware and I need to get as much detail as
possible about what is wrong with the XML, I find the validation error
reporting in JAXB insufficient. For instance, if a field-length validation
error occurs, I'd like to be able to determine which element caused the
problem. Or if a required field is missing, I'd like to know which one,
rather than the one that was unexpectedly found in its place. There's one
error that deserves a special mention as the cause of many an afternoon's
frustration: "a required object is missing" - can't it say which one?

This problem is exacerbated because I can only use on-demand validation
(explained in my previous post). This means that I have to generate isSet
methods for all my mandatory elements and call them in code before
marshalling in order to avoid the "a required object is missing" errors.
This adds a significant coding overhead.

To work-around this problem, I have created a java class for each schema
that I use to do the validation in code. This means that my validation
rules now exist in schema and in code, which is not pleasant! I guess I
could remove them from the schema, but I live in hope that some day I'll be
able to get rid of my validation code so I've been keeping the code and
schema rules synchronised.

I know this topic has cropped up before, and I'd be curious to see how other
people have addressed these problems. I remember the JAXB team asking for
feedback on what information users would like in validation error reports
and how they'd use it. Was much feedback received?

Whilst I wait for potential improvements which would allow me to throw away
my code, I was wondering if there's some way to access the actual schema
rules from within code. I know it's solving the wrong problem, but at least
I wouldn't have to keep my two sets of rules in sync then.

Regards,

Marcus