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

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.

Reply via email to