• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic