I have the following document:
<a> <bb>abc</bb> <cc>ccc</cc> <dd>ddd</dd> </a> <a> <bb>zz</bb> <cc>1</cc> <dd>2</dd> </a>
How can I get the value of <cc>
using XPath if <bb>
is zz
?
Select all A sibling elements that precede the context node. > Select all A sibling elements that follow the context node. > Select all sibling elements that precede the context node. > Select the first preceding sibling element named A in reverse document order.
XPath assertion uses XPath expression to select the target node and its values. It compares the result of an XPath expression to an expected value. XPath is an XML query language for selecting nodes from an XML. Step 1 − After clicking Add Assertion, select Assertion Category – Property Content.
//div[@class='content'][2] means: Select all elements called div from anywhere in the document, but only the ones that have a class attribute whose value is equal to "content". Of those selected nodes, only keep those which are the second div[@class = 'content'] element of their parent.
Not sure why everybody is querying for siblings, you can also check for <bb/>
-elements matching the predicate from <a/>
's predicate:
//a[bb/text() = "zz"]/cc/text()
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