如何使用同一节点中其他属性的值获取属性值?XML XPath [英] How do i get a value of attribute using the value of other attribute in same node ? XML XPath

查看:37
本文介绍了如何使用同一节点中其他属性的值获取属性值?XML XPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用 XMLPath 使用其他 @ 引用来获取 @ 的值?

hi how do i can get the value of @ using other @ refferencing using XMLPath?

例如:

如何获取 id 1 的值名称?

how do i get the value name of id 1?

将选择 id 为 1 的属性,但我想获取 name 属性的值,该属性返回Camisa de Seda",类似于:/items/item[@id="1"]@name(对吗??)

ill select the attribute with id 1, but i would to get the value of name attribute, who returns "Camisa de Seda" something like: /items/item[@id="1"]@name (is this right?)

itemDb.xml:

itemDb.xml:

<items>

<item id="0" name="Armadura de Couro">
    <attribute key="type" value="armadura"/>
    <attribute key="price" value="100"/>
</item>

<item id="1" name="Camisa de Seda">
    <attribute key="type" value="armadura"/>
    <attribute key="price" value="50"/>
</item> 

</items>

推荐答案

如果你已经知道@Id 属性的值并且想要返回对应的@name 属性值那么你贴的代码几乎是正确的,试试这个一:

If you already know the value of the @Id attribute and you want to return the corresponding @name attribute value then the code you posted is almost correct, Try this one:

 //items/item[@id="1"]/@name

这篇关于如何使用同一节点中其他属性的值获取属性值?XML XPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆