Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using DOM - Can I get the line number for a node

 
PETER LAKE
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
PETER LAKE
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic