Choosing XPath in Inner Text

I am trying to extract an element with specific inner text from a parsed XML document. I know that I can select an element that has a child with a specific inner text using //myparent[mychild='foo'] , but I just want to select the “mychild” element in this example.

 <myparent> <mychild> foo </mychild> </myparent> 

What will be the XPath query for "foo" that will return a "mychild" node?

+44
xml xpath
Jan 04
source share
2 answers

Have you tried this?

 //myparent/mychild[text() = 'foo'] 

Alternatively, you can use the shortcut for the self axis:

 //myparent/mychild[. = 'foo'] 
+68
Jan 04 '10 at
source share

Matt said this, but the complete solution: // myparent [mychild = 'foo'] / mychild

+3
Dec 30 2018-12-12T00: 00Z
source share



All Articles