简体   繁体   English

XPath查询以解析xml属性文件

[英]XPath query to parse xml properties file

I have the following xml document: 我有以下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>

I am executing the following xpath query: 我正在执行以下xpath查询:

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

I anticipate this to return HappyKey, however it returns nothing. 我预计这将返回HappyKey,但是它什么也不会返回。

如果仅在寻找值,请尝试:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM