From: Ken Date: 2006-10-07T01:35:14+09:00 Subject: Re: Parse and modify an XML file with REXML Actually, none of this will work. You can't do what you're trying to do because preceding-sibling will look at all the preceding siblings. So you'll find your first 203 gets reported correctly as being "after" 202. But all of the other 203's in your XML will also say they are after 202 -- because they are! If you put a yield statement in your events.each iterator, you'll see what I mean. It will report the first 203 correctly. The loop will break that that point because yield will tell you that you have no block. But the point is when you take out yield, you'll see that your output is all the 203's. The issue is that you're trying to do two predicates at the same time. That can work (just have two bracketed groups), but not with how you are trying to do it in this case. I'd recommend just treating the XML file like a regular old text file and parse it line by line with regular expressions. Don't even use an XML parser.