找到值的xpath

时间:2015-09-15 14:36:14

标签: xml xpath xml-parsing xpath-2.0

我想从xPath获取以下xml的值{namevalue1}。

<?xml version="1.0" encoding="UTF-8" ?>
<properties>
    <entry key="name1">namevalue1</entry>
    <entry key="name2">namevalue2</entry>
</properties>

value1的xPath是什么?

2 个答案:

答案 0 :(得分:1)

要扩展Jeff提出的内容,您需要附加一个text()来获取文本节点:

% < in.xml 
<?xml version="1.0" encoding="UTF-8" ?>
<properties>
    <entry key="name1">namevalue1</entry>
    <entry key="name2">namevalue2</entry>
</properties>
% xpquery '/properties/entry[@key="name1"]/text()' in.xml
namevalue1
%

答案 1 :(得分:1)

尝试使用:

/properties/entry[@key='name1']/text()