gpt4 book ai didi

html - 返回由 html 标记拆分的字符串连接的 XPath

转载 作者:行者123 更新时间:2023-11-27 23:09:25 25 4
gpt4 key购买 nike

如何使用 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 表达式中这可能吗?

最佳答案

XPath 1.0

无法使用纯 XPath 1.0。相反,选择 div 元素:

//div

然后在托管 XPath 库调用的语言中对每个 div 元素的字符串值应用空间规范化。

XPath 2.0

这个 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.

根据要求。

关于html - 返回由 html 标记拆分的字符串连接的 XPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46995268/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com