XPath 返回符合条件的子节点值的字符串连接 [英] XPath to return string concatenation of qualifying child node values

查看:27
本文介绍了XPath 返回符合条件的子节点值的字符串连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以建议一种 XPath 表达式格式,它返回一个字符串值,其中包含元素的某些合格子节点的连接值,但忽略其他:

应返回此文本节点.<em>以及这个元素的值.</em>和这个.<p>但是这个段落元素应该被忽略.</p>

返回值应该是单个字符串:

应该返回这个文本节点.以及这个元素的值.和这个.

这可以在单个 XPath 表达式中实现吗?

谢谢.

解决方案

在 XPath 1.0 中:

你可以使用

/div//text()[not(parent::p)]

捕获想要的文本节点.连接本身无法在 XPath 1.0 中完成,我建议在宿主应用程序中完成.

Can anyone please suggest an XPath expression format that returns a string value containing the concatenated values of certain qualifying child nodes of an element, but ignoring others:

<div>
    This text node should be returned.
    <em>And the value of this element.</em>
    And this.
    <p>But this paragraph element should be ignored.</p>
</div>

The returned value should be a single string:

This text node should be returned. And the value of this element. And this.

Is this possible in a single XPath expression?

Thanks.

解决方案

In XPath 1.0:

You can use

/div//text()[not(parent::p)]

to capture the wanted text nodes. The concatenation itself cannot be done in XPath 1.0, I recommend doing it in the host application.

这篇关于XPath 返回符合条件的子节点值的字符串连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆