Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

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

 
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.
 
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
Boost this thread!