views:

33

answers:

1

I have the following xml document:

<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"&gt;  
<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:

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

I anticipate this to return HappyKey, however it returns nothing.

+2  A: 

If you are looking for the value only then try:

/properties/entry[@key='HappyKey']/text()
XPath is a hosted language. So, to access the `entry` element string value, or the string value of all `entry` element's childs text nodes (this is what your expression means) is a matter of the host language.
Alejandro