获取嵌套XML中的Xpath节点值
我的xml结构就像获取嵌套XML中的Xpath节点值,xml,xpath,Xml,Xpath,我的xml结构就像 <items> <item> <brand> <id> 3 </id> </brand> <product> <productType>Type 1</productType> </product> </item> <item> <brand>
<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>
但它不起作用。正确的xpath表达式是什么。您有一个简单的嵌套问题,因为
品牌
是产品的同级产品
,而不是xpath查询所暗示的应答器
只需更改为:
/items/item[brand/id = 3]/product/productType
结果:
Element='<productType>Type 1</productType>'
Element='Type 1'
试试看
Element='<productType>Type 1</productType>'