开发者

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.

Is there any other way to skip the span element? Is it possible to somehow join the matches?


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜