非空元素选为空

时间:2014-03-12 06:41:53

标签: xpath

我的xml有很多以下元素的外观:

<attribute>
<attributeCode>aaa</attributeCode>
<attributeName>bbb</attributeName>
<attributeType>ccc</attributeType>
<attributeValue>ddd</attributeValue>
</attribute> 

我使用xpath表达式返回     &#39; //属性/的attributeName [的attributeName =&#34; BBB&#34;]&#39; 它工作正常,但我需要返回attributeValue所以我改为:     &#39; //属性/的AttributeValue [的attributeName =&#34; BBB&#34;]&#39; 我希望能得到这样的信息。但它返回空值。有什么问题?

1 个答案:

答案 0 :(得分:1)

由于您选择了attributeValue,因此您需要先转到父元素,以检查attributeName

这将有效(注意:../):

//attribute/attributeValue[../attributeName='bbb']