XPath problem with skipping the element / joining matches
This is the data:
<p>
<span class="z">XXX</span><br/>
123456<br/>
78910</p>
There are also whitespaces and newlines all over the place.
I need to get only '<br/&开发者_开发问答gt;123456<br/>78910
' skipping the span element.
When I run this xpath: '//p/text()' I get 3 matches: The first - a bunch of spaces and newlines, the second one with 123456 and the third one with 78910.
It looks like you are trying to select every node after the span
element:
/p/span/following-sibling::node()
If you want the text node children without the white space only text nodes:
/p/text()[normalize-space()]
Use:
/p/node()[not(self::span) and (not(self::text[not(normalize-space())]))]
This selects all nodes that a children of the top element p
and that if they are text nodes they are not white-space only.
精彩评论