I have the following xml file:
<product>
<typelist>
<type id="6666" name="Six">
<itemTypeList>
<itemtype id="1" name="Six-1"/>
<itemtype id="2" name="Six-2"/>
</itemTypeList>
<typeInstance id="111" type="1"/>
<typeInstance id="222" type="2"/>
</type>
<type id="8888" name="Eight">
<itemTypeList>
<itemtype id="1" name="Eight-1"/>
<itemtype id="10" name="Eight-10"/>
<itemtype id="9" name="Eight-9"/>
<itemtype id="2" name="Eight-2"/>
</itemTypeList>
<typeInstance id="1111" type="1"/>
<typeInstance id="2222" type="10"/>
<typeInstance id="3333" type="9"/>
<typeInstance id="4444" type="2"/>
</type>
</typelist>
<list>
<product id="1" name="Product1" type="6666"/>
<product id="2" name="Product2" type="6666"/>
<product id="12" name="Product12" type="8888"/>
<product id="13" name="Product13" type="8888"/>
</list>
</product>
I need to get a list of itemtype with type information:
6666, Six, 111, 1
6666, Six, 222, 2
8888, Eight, 1111, 1
8888, Eight, 2222, 10
8888, Eight, 2222, 10
8888, Eight, 3333, 9
8888, Eight, 4444, 2
How can I do it using xpath? I was trying to use something like to get the typeid for each item, but it only returns me the first occorrence (does not repeat for each grandchildren node):
xpath(xmldata, 'product/typelist/type/itemTypeList/itemtype/id/../../@id)
Is there a way to get the desired result using Xpath 1.0?
Best
No comments:
Post a Comment