xpath based on condition in java

d3death

New Member
I have an xml of the following structure:\[code\]<Root> <Sample> <Materil material_class="book" /> <Book Name="harry" Price="8" /> <Book Name="small things" Price="9" /> <Book Name="snow" Price="10" /> </Sample> <Commodity> <Sample> <Materil material_class="sub" /> <Book Name="sherin" Price="8" /> <Book Name="bigthings" Price="9" /> <Book Name="leopard" Price="10" /> </Sample> <Commodity> <Sample> <Materil material_class="sub" /> <Book Name="azxcv" Price="86" /> <Book Name="ddddd" Price="79" /> <Book Name="qwert" Price="810" /> </Sample> </Commodity> <Commodity> <Sample> <Materil material_class="subtwo" /> <Book Name="ratnam" Price="86" /> <Book Name="shantharam" Price="99" /> <Book Name="da vinci" Price="10" /> </Sample> </Commodity> </Commodity></Root>\[/code\]Is there a way to iterate this xml based on condition like,if the \[code\]material_class = "sub"\[/code\], iterate the \[code\]Book\[/code\] tag below that and store the \[code\]@Name\[/code\] and \[code\]@Price\[/code\] . If the \[code\]material_class = "book"\[/code\], iterate the \[code\]Book\[/code\] tag below that. Also i want to get the length of number of \[code\]/Root/Commodity/Commodity\[/code\] tags (in this case , it is two). Any help is appreciated. I am new to XPath.
 
Back
Top