在XPATH中获取部分节点 [英] Get partial node in XPATH

查看:63
本文介绍了在XPATH中获取部分节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我具有以下XML

Suppose I have the following XML

<a>
    <b></b>
    <c></c>
    <d></d>
    <e></e>
</a>

如果我想获得所有 a 的孩子,除了 d 。为此,我将使用以下内容:

If I want to get a all children of a except d. For that, I would use the following:

/a/*[not(self::d)] 

但是,这将返回 b c 和<在三个单独的节点中的strong> e 。我要查找的只是一个节点,包含 b c e ,但不包括 d 。它将类似于以下伪代码:

However, this would return b, c, and e in three separate nodes. What I am looking for is only one node, containing b, c, and e, excluding d. It would be something simlar to the following pseudo code:

/a/* and <do not include /a/d please>

这可能吗?

谢谢。

推荐答案

XPath-无论版本1.0、2.0还是3.0-只能查询子树,并且不能修改(包括

XPath - no matter whether version 1.0, 2.0 or 3.0 - can only query subtrees and is not capable to modify (which includes removing) or construct new elements.

为此,您将不得不使用XQuery或XSLT,或者在查询语言之外修改文档,而仅使用XPath选择结果子树,然后使用另一个XPath选择不需要的节点,并使用您正在使用的编程语言将其从结果中删除。

You would have to use XQuery or XSLT for this purpose, or modify the document outside the query language and only use XPath to select the result subtree, afterwards use another XPath to select the nodes you do not want and remove them from the result in the programming language you're using.

这篇关于在XPATH中获取部分节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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