Reputation: 964
I doubt there is a way to get the element which has a particular value (text) from xml document using xpath.
<domain log-root="/logs" application-root="/applications"><resources>
<jdbc-resource pool-name="SamplePool" jndi-name="jdbc/sample" />
<jdbc-resource pool-name="TimerPool" jndi-name="abc">text1</jdbc-resource>
<jdbc-resource pool-name="TimerPool" jndi-name="def">text2</jdbc-resource>
<jdbc-resource pool-name="TimerPool" jndi-name="ghi">text3</jdbc-resource></resources</domain>
/domain//jdbc-resource[@pool-name='TimerPool']/text()='text2'
Please post your ideas if there is any.
Upvotes: 0
Views: 362
Reputation: 243449
Use:
/domain/*/jdbc-resource[@pool-name='TimerPool' and .='text2']
or you may use:
/domain/*/jdbc-resource[@pool-name='TimerPool'][.='text2']
Both expressions above select all jdbc-resource
elements the string value of whose pool-name
attribute is "TimerPoool"
and whose string value (of the jdbc-resource
element) is "text2"
and that are grand-children of the top element of the XML document.
Upvotes: 3
Reputation: 7569
Well, text() should do. http://www.w3schools.com/xpath/xpath_examples.asp
Have you tried it already? Also, check the path, it could be
//jdbc-resource[@pool-name='TimerPool']/text()='text2'
or
/domain/resource/jdbc-resource[@pool-name='TimerPool']/text()='text2'
or
//resource/jdbc-resource[@pool-name='TimerPool']/text()='text2'
Upvotes: -1