Given the following XML:
<root>
<li><span>abcText1cba</span></li>
<li><span>abcText2cba</span></li>
</root>
I want to select all li
elements having a span
child node containing an inner text of Text1
- using an XPath.
I started off with /root/li[span]
and then tried to further check with: /root/li[span[contains(text(), 'Text1')]]
However, this does not return any nodes. I fail to see why, can somebody help me out?
Show(val. ToString()); I would paste the XPath value in TextBox2, which should inspite give my the inner text corresponding to the XPath.
As defined in the W3 XPath 1.0 Spec, " child::node() selects all the children of the context node, whatever their node type." This means that any element, text-node, comment-node and processing-instruction node children are selected by this node-test.
The key part of this XPath is *[1] , which will select the node value of the first child of Department .
Just for readers. The xpath is correct. OP: Perhaps xpath parser didnt support the expression?
/root/li[span[contains(text(), "Text1")]]
//li[./span[contains(text(),'Text1')]] - have just one target result
//li[./span[contains(text(),'Text')]] - returns two results as target
This approach is using something that isn't well documented anywhere and just few understands how it's powerful
Element specified by Xpath has a child node defined by another xpath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With