I have an XML file:
<products>
<foundation label="New Construction">
<series label="Portrait Series" startImg="img/blank.png">
<item_container nr="1" label="Firebed">
<item next="11" id="" label="Logs Black Brick">img/PortraitSeries/logs-black-brick.png</item>
<item next="12" id="" label="Logs Red Brick">img/PortraitSeries/logs-red-brick.png</item>
</item_container>
<item_container nr="2" label="Fronts">
<item next="21" id="569LFP" label="Ledge Front - Patina">img/New_PortraitSeries/patina_front.png</item>
<item next="22" id="569LFB" label="Ledge Front - Black">img/New_PortraitSeries/black_front.png</item>
</item_container>
</series>
</foundation>
</products>
</meh>
I'm using Nokogiri to parse. What I want to do is operate on each item
element within the scope of each item_container
. Meaning, I want to do certain things with each item
while knowing which item_container
they are under.
Here is some code to get at the first item_container:
foundation = @doc.at_xpath("//foundation")
ic = foundation.children.xpath("//series").children.xpath("//item_container")[0]
That's all good. Now, I would assume that:
ic.children.xpath("//item")
would return just the first two items, the two under the first item_container
. However, it returns all four items which I don't understand.
How can I just access the first two items?