Getting Xpath node values in nested XML -


my xml structure like,

<items> <item>     <brand>         <id> 3 </id>      </brand>     <product>         <producttype>type 1</producttype>     </product> </item> <item>     <brand>         <id> 4 </id>      </brand>     <product>         <producttype>type 2</producttype>     </product> </item> </items> 

i need product type value if user provides brand id. eg, if user enters brand id 3, need return product type type 1

i tried xpath expression

 /items/item/brand[id = 3]/product/producttype 

but not work. correct xpath expression.

you have simple nesting problem since brand sibling product , not anscestor xpath query implies.

simply change to:

/items/item[brand/id = 3]/product/producttype 

result:

element='<producttype>type 1</producttype>' 

try @ http://www.freeformatter.com/xpath-tester.html.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -