开发者

how to use XPath query to get text under certain element but not in any element?

开发者 https://www.devze.com 2023-03-09 21:59 出处:网络
Not sure if this title make sense. The piece of HTML is like this: <div id=\"A\"> <span class=\"B\"> XXXX </span>

Not sure if this title make sense. The piece of HTML is like this:

<div id="A">
  <span class="B"> XXXX </span>
  MMM
  <sp开发者_如何学编程an class="B"> ZZZZ </span>
  NNN
  <div class="C">
    <span class="B">
      OOO
    </span>
  </div>
</div>

How to use XPath query pattern to get the text "MMM" and "NNN" ?

Thank you.


If you want the text for a node with a particular id, then use the following expression:

//div[@id='A']/text()


In this case you can just use /div/text() to get any text nodes under the initial div root. You'd only get all text nodes if you did //text()

0

精彩评论

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