Reputation: 37700
Like in this question I am trying to record the exact position when parsing XML.
I already use the SAX Locator
passed to setDocumentLocator()
to record the line and column number but that doesn't give the offset from the beginning of the file. Is there a way to find the number of bytes read so far by the SAX parser or offset of each line without re-reading the whole file?
Upvotes: 2
Views: 1334
Reputation: 37700
I found another question and answer which suggests using an XMLStreamReader instead of SAXParser because it has getLocation().getCharacterOffset()
instead. It already has exactly what I need.
Upvotes: 1
Reputation: 3199
Hypothetically, you can use the CountingInputStream from Apache commons IO.
Upvotes: 1