Search code examples
javaxmlattributesstaxwoodstox

StAX/StAX2 attributes' location in source XML


I need to get the offsets (start and end location) in source XML for each extracted text information.

I need to use the XML PULL READING model, so I've been experimenting with StAX and StAX2 (Woodstox) for some time.

Original StAX contains API:

javax.xml.stream.Location

However, this class is rather obscure. So here goes the StAX2 (Woodstox) which contains an improved API:

org.codehaus.stax2.LocationInfo

It works nicely for elements and stuff via the LocationInfo.

My problem: How can I get the offset of attributes since they are apparently a part of element? So the location's granuarity is on element level -> I can get offsets for entire element and not for each attribute...

Thanks in advance!


Solution

  • Woodstox does not track starting/ending offsets for attribute values, only for elements.