如何使用XPath表达式返回包含连接值的字符串值?
<div>
This text node (1) should be returned.
<em>And the value of this element.</em>
And this.
</div>
<div>
This text node (2) should be returned.
And this.
</div>
<div>
This text node (3) should be returned.
<em>And the value of this element.</em>
And this.
</div>
返回的值应该是由div
元素分隔的字符串数组:
"This text node (1) should be returned. And the value of this element. And this."
"This text node (2) should be returned. And this."
"This text node (3) should be returned. And the value of this element. And this."
这是否可以在单个XPath表达式中使用?
答案 0 :(得分:2)
无法使用纯XPath 1.0。而是选择div
元素:
//div
然后对托管XPath库调用的语言中的每个div
元素的字符串值应用空间规范化。
此XPath 2.0表达式,
//div/normalize-space()
将返回文档中所有div
元素的规范化字符串值:
This text node (1) should be returned. And the value of this element. And this.
This text node (2) should be returned. And this.
This text node (3) should be returned. And the value of this element. And this.
按要求。