Question

Overview: I am using StAX (Java) to parse an XML file. However, I need to be able to return to a specified position in the file (like marking a point in a stream).

Question: I was wondering whether there was a way to call a method to mark a position in a file, read some events but then have the reader move back to the mark.

Reasoning: I have xml statements such as:

<user>
<id>001</id>
<name>test</name>
<game>test game</game>
</user>

I would like to have the reader search through the file and when it finds a matching id or name I then need it to be able to go back and collect any required information on the user such as the game, etc. I am not experienced in XML but I assume that for a robust method, it must not depend on the order of the inner tags but rely purely on the basis that they are present. Is that right? If so then once a matching id is found, the reader must be able to go back and check each of the tags within the <user> tag.

Many thanks

Était-ce utile?

La solution

The Stax API only goes forward and never backward.It is a low level API which can be used as a foundation for more advanced APIs. In your case one possible solution is to store the data temporarily(e.g. in a hashmap).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top