开发者

XPath query to get a descendant node of another node

开发者 https://www.devze.com 2023-03-30 04:38 出处:网络
I have the following HTML code <html> <body> ~~ optional text and variably-nested elements ~~

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'].

0

精彩评论

暂无评论...
验证码 换一张
取 消