XPath query to get a descendant node of another node
I have the following HTML code
<html>
<body>
~~ optional text and variably-nested elements ~~
<div class="a">
~~ optional text and variably-nested elements ~~
<div class="b">example</div>
~~ optional text and variably-nested elements ~~
</div>
~~ optional text and variably-nested elements ~~
<div class="c">
~~ optional text and variably-nested elements ~~
<div class="b">example</div>
~~ optional text and variably-nested elements ~~
</div>
~~ optional text and variably-nested elements ~~
</body>
</html>
I would like to retrieve the <div class="b">
DOMNode of the <div class="c">开发者_如何学JAVA;
.
I have used:
//*[@class='b']
but it produced wrong results. What would be the correct XPath query to use?
Thanks
Try with
"//*[@class='c']//*[@class='b']"
http://codepad.org/EzBAWDPg
Use this XPath: //div[@class = 'c']/div[@class = 'b']
.
It will select div[@class = 'b']
which is child of div[@class = 'c']
.
精彩评论