When processing XML, is there a way to check what the previous and what
the next “rows” are?
That probably makes no sense without context, so here is an example. I
need to find things in the XML based on rules. For example, one rule
might be “find the first 203 that comes after 202.” Another rule is
“Find the first 203 that comes before 16.” So say I have this:
I have to be able to find that the element after 202 is 203. (As
opposed to a situation where a 202 appeared, but the next element was
not 203.) I then have to determine that the element after a given 203
is 16. Then I have to change the value attribute of the first and last
203 elements. So the XML, after applying the rules, would look like
The 202 and 16 are essentially bracketers of data, in this case. There
can be many such groups in the XML that look like this.
I know how to parse through XML using XPath or using a stream listener.
I have read the tutorial that comes with REXML. But what I’m not sure
how to do is check for the conditions like I described above. One
thought was I could read the XML into an array because then I get an
enforced “line numbering” with the indexing. So I could check
currentLine - 1 and currentLine + 1. I’m not sure if that is a smart
Has anyone done something similar in their work?