[jdom-interest] Getting more detail from JDOMException.

Kesav Kumar kesavk at voquette.com
Mon Oct 16 10:17:17 PDT 2000

I also faced this problem for getting column number from the Exception.
Actually SAXParseException gives more information than JDOMException gives.
I modified the SAXBuilder.java at line number 306 to make the
SAXParseException as rootException.

if(e instanceof SAXParseException)
	throw new JDOMException(e.getMessage(), e);

This way in my program I can get the rootCause and cast to SAXParseException
to get the line number, column number and systemeid.  I don't know is this
correct way of fix, I just did on my local version.

Kesav Kumar
Software Engineer
Voquette, Inc.
650 356 3740
mailto:kesavk at voquette.com

-----Original Message-----
From: Travers Waker [mailto:traversw at innoforge.co.za]
Sent: Friday, October 13, 2000 2:14 PM
To: jdom-interest at jdom.org
Subject: [jdom-interest] Getting more detail from JDOMException.


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.


To control your jdom-interest membership:

More information about the jdom-interest mailing list