我的XML如下:
<prop type="x-ConfirmationLevel">Approved</prop>
<prop type="x-Internal project number:SingleString">O-74205</prop>
<prop type="x-Product Line:MultiplePicklist">Services</prop>
<prop type="x-Product Line:MultiplePicklist">Raman</prop>
<prop type="x-Product Line:MultiplePicklist">Support</prop>
,当我
我的Xpath如下:
//prop[@type = "x-Product Line:MultiplePicklist" and text() = "Raman"]
在我的XML中,Xpath应该仅返回O-74025。
有什么主意吗?谢谢!
答案 0 :(得分:1)
喜欢这个:
<?xml version="1.0"?>
<root>
<x>
<prop type="x-ConfirmationLevel">Approved</prop>
<prop type="x-Internal project number:SingleString">O-74205</prop>
<prop type="x-Product Line:MultiplePicklist">Services</prop>
<prop type="x-Product Line:MultiplePicklist">Raman</prop>
<prop type="x-Product Line:MultiplePicklist">Support</prop>
</x>
<x>
<prop type="x-ConfirmationLevel">Approved</prop>
<prop type="x-Internal project number:SingleString">O-74205</prop>
<prop type="x-Product Line:MultiplePicklist">Services</prop>
<prop type="x-Product Line:MultiplePicklist">Foobar</prop>
<prop type="x-Product Line:MultiplePicklist">Support</prop>
</x>
</root>
xmllint --xpath '
//prop[@type="x-Product Line:MultiplePicklist" and \
text()="Raman"]/../prop[@type="x-Internal project number:SingleString"]/text()
' file.xml
O-74205
答案 1 :(得分:1)
只需在表达式中使用parent::node()引用:
//prop[@type = "x-Product Line:MultiplePicklist" and text() = "Raman"]/parent::node()/prop[@type = "x-Internal project number:SingleString"]/text()