XMLStreamReader byte location missmatch
Hello,
I am trying to parse a XML file and want to store the byte positions of start and closing tags so I can later use RandomAccessFile to get a particular xml element.
This should be used to access very big xml files. I want to be able to pull out a arbitrary xml element given only the xpath expression from the root element.
But I am having some trouble with it.
I tried to use XMLStreamReader to parse the XML and getLocation to get the byte offset, but the position I get when a START_ELEMENT event occurs is not the start of the XML tag! It is somewhere after that. I have even tried to use the previous or next positions, but none of them fits the start tag.
XMLInputFactory xif = XMLInputFactory.newInstance();
XMLStreamReader xsr = xif.createXMLStreamReader(is);
while ( xsr.hasNext() ){
if (xsr.isStartElement()){
int currentPos = xsr.getLocation().getCharacterOffset();
System.out.print("current position: " + currentPos);
}
}
It would be very helpful if somebody could give me a hint as how to solve my problem or where to find a better way to do this.
Thanks a lot!

