how to use XPath query to get text under certain element but not in any element?
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()
精彩评论