用于解析xml属性文件的XPath查询

时间:2010-08-10 20:44:18

标签: xml xpath properties

我有以下xml文档:

<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">  
<properties>  
    <comment>My Happy Configuration</comment>  
    <entry key="HappyKey">Happy Key</entry>  
    <entry key="SadKey">Sad Key</entry>  
    <entry key="AngryKey">Angry Key</entry>  
    <entry key="ConfusedKey">Confused Key</entry>  
    ...
</properties>

我正在执行以下xpath查询:

/properties/entry[@key='HappyKey']  

我预计这将返回HappyKey,但它不返回任何内容。

1 个答案:

答案 0 :(得分:2)

如果您只想查找该值,请尝试:

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