如何使用xpath从节点获取属性值?

时间:2012-11-02 11:18:56

标签: xml string xpath return-value

xpath完全是新手。

我有xml:

<Values>
   <Value Value="a" CustomAtr="1" />
   <Value Value="b" CustomAtr="2" />
   <Value Value="c" CustomAtr="3" />
</Values>

要按索引获取价值,我可以使用:string(/*/Value[1]/@CustomAtr)

是否有可能通过钥匙获得价值? 热门CustomAtrValue="b"

谢谢

1 个答案:

答案 0 :(得分:38)

这应该可以解决问题:

string(//Value[@Value='b']/@CustomAttr)
相关问题