1

Does anyone know how you can get the line number of an Element in a Document?

I appreciate this information is probably not stored on the Element once it is parsed (I looked) but is there some way during the parsing process of capturing line numbers of each elements? I can then use a lookup later to go from Element -> line number.

Mike Q
  • 22,839
  • 20
  • 87
  • 129
  • I don't believe you can accomplish this with any of the DOM parsers, but you might be able to with SAX, or a StAX implementation which parses in a stream. – Spencer Kormos Apr 17 '12 at 15:56
  • I once did this for JDOM (links [here](https://stackoverflow.com/questions/7501326/finding-the-exact-location-of-an-element-in-a-xml-document)). I thought the general process should be similar for DOM4J, but after a quick look, it seems a lot harder in DOM4J, unfortunately. – forty-two Apr 19 '12 at 08:46

0 Answers0