[jdom-interest] Getting more detail from JDOMException.

Travers Waker traversw at innoforge.co.za
Fri Oct 13 14:13:59 PDT 2000


I'm using JDOM (Xerces) to parse and validate (using a schema) an XML
document.  When schema validation fails, for example, because the content of
a particular element did not match the regualr expression it was meant to
match, a JDOMException is thrown.  This exception contains information about
the content of the element, the regualr expression that was not matched, and
the line number (in the XML document) that validation failed on.  However,
this is sometimes not accurate enough to identify exactly which element
failed validation, because although the JDOMException specifies what the
actaul content was and what regular expression or datatype was not matched
by this content, it does not reveal the name of the element.  The line
number is often not useful because the messages I get in on a socket often
have the whitespace striiped off them and are therefore consist only of a
single line.

I notice that the org.xml.sax.SAXParseException class provides more
information about the cause of the Exception than JDOMException provides.
It can identify the column in which the cause of the Exception is located,
which, when combined with the line number, exactly locates the cause of the
Exception.  It also provides a getPublicId() method that identifies the
element causing the Exception by name.

Unfortunately, It doesn't seem possible (to me) to get to the
SAXParseException that, I assume, resulted in the JDOMException.  For
example, consider the following JDOMException:

org.jdom.JDOMException: Datatype error: Value '0000021' does not match
regular expression facet '\d{1,6}'..: Error on line 1: Datatype error: Value
'0000021' does not match regular expression facet '\d{1,6}'..

When I try JDOMException.getRootCause(), I get a handle to another
JDOMException.  When I call getRootCause() on that JDOMException, I get
null.  It doesn't seem possible to get to the SAXParseException and the
extra (useful) information it contains.

Does anyone have a way for me to identify the cause of JDOMExceptions
resulting from failed schema validation with more accuracy than
JDOMException is providing at the moment?

Thanks for any help.


More information about the jdom-interest mailing list