Hi Joe,

[EMAIL PROTECTED] wrote on 10/27/2008 05:25:25 PM:

> > Thanks for your response, but I'm not looking for column and row
> > numbers in the XML document.  I might have been a little ambiguous
> > in using the word "location".  What I need is the reference to the
> > Node object in the DOM tree that caused the validation error.  The
> > perfect solution would be for the SAXException to contain a
> > reference to that Node.
>
> If you're working with SAX, there may not be any DOM nodes, of
> course... so I'd rather see a more general solution.

... except that he's not working with SAX. The input passed in is a DOM.

Like DocumentBuilder [1] the JAXP Validator [2] reuses classes from the SAX
API instead of inventing yet another set of ErrorHandler and exception
classes specific to JAXP. SAXException is thrown from the Validator when
there's an error. Doesn't matter what the Source type is.

> Instead, I'd suggest reporting an XPath to the node in question.
> That will work against a DOM already in memory, but would also work
> for documents loaded later, including those loaded into an XML
> API... and it's human-readable enough to be chased down in a text
> editor or debugger if necessary.
>
> Generating an XPath to a node is fairly easy if you have an in-
> memory model of the document such as a DOM. (It's made a bit uglier
> by namespaces, but there are standard ways to handle that; I've
> written that code in both XSLT and Java.) In a SAX parser, where you
> can't necessarily chase back up the tree, it would require
> maintaining what amounts to a context stack with some counters...
> easy to do if you're willing to generate ugly paths like /node()[1]
> /node()[5]/@foo. Somewhat more expensive if you want that something
> more human-friendly like /baz/bar/@foo. Of course you probably
> wouldn't want to pay that overhead except when debugging; this might
> want to be an optional plug-in event filter layer.

Can't reliably build an XPath which identifies the location of the error
with the standard JAXP APIs. See my last response on this subject in the
archives [3].

Thanks.

[1]
http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/parsers/DocumentBuilder.html
[2]
http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/validation/Validator.html
[3] http://marc.info/?l=xerces-j-user&m=107375672210434&w=2

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [EMAIL PROTECTED]
E-mail: [EMAIL PROTECTED]

Reply via email to