Howdy folks, I am using DOM to parse an XML document. I am validating the document (not in XML/DTD sense) to ensure it is ready to be used by the server software. At a particular node (which may have an error) I would like to return the offending line number to the user. Is this possible? I know if I was using SAX parser - I could get the Locator. Can't seem to do this when using DOM. Peter.
It's not a 100% sure thing, but AFIK you should implement the ErrorHandler interface. It should return you the line number on which the error occured. You set it like this aDocumentBuilder.setErrorHandler(new anErrorHandler); It has 3 methods to be implemented and should do the trick.
Joined: Aug 22, 2001
Sven, Thanks for the reply. I would agree with you if it was a parser error that occurred - for example a missing tag. But I determine the error via routines that I have written. I want to report the line number of the node that I have a problem with. Peter.