3

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

4

1 回答 1

2

Stax API 只进不退。它是一个低级 API,可以用作更高级 API 的基础。在您的情况下,一种可能的解决方案是临时存储数据(例如在哈希图中)。

于 2013-07-12T12:36:21.053 回答