为什么没有名称空间限定节点的XPath语法? [英] Why is there no XPath syntax for namespace-qualified nodes?

查看:61
本文介绍了为什么没有名称空间限定节点的XPath语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XML文档中的某些节点具有命名空间,这些命名空间使用已定义的前缀指定.

Some of the nodes in an XML document have namespaces, specified with a defined prefix.

可以在XPath 1.0中指定 local-name(),因此可以忽略名称空间.

It is possible to specify local-name() in XPath 1.0 and so ignore namespaces.

但是,我想让XPath的编写者能够使用其完整的名称空间限定名称作为标识符来查找节点.

However, I want to enable the writer of the XPath to find nodes using their full namespace-qualified name as an identifier.

推荐的方法是在调用代码(在我的情况下为Java)中添加名称空间声明.但这意味着编写Xpath的人无法使用名称空间!

The recommended way is to add namespace declarations in the invoking code (in my case, Java). But this means that the person writing Xpath does not have the ability to work with namespaces!

我们如何使用纯XPath按节点的完全限定名称查找节点?

How do we find nodes by their fully qualified names using pure XPath?

推荐答案

不确定作为标识符"的含义.

Not sure what you meant by "as an identifier".

我们如何使用纯XPath按节点的完全限定名称查找节点?

How do we find nodes by their fully qualified names using pure XPath?

在XPath 1.0中,通过使用local-name()和命名空间-uri(),例如

In XPath 1.0, by using local-name() and namespace-uri(), e.g.

"*[local-name() = 'foo' and namespace-uri() = 'http://my.org/ns/2.0']"

在XPath 2.0中,有一组与名称空间相关的丰富功能,例如 namespace-uri-from-QName() .但是我不确定他们是否会在您想要的上述方面有所改善.

In XPath 2.0, there is a richer set of functions related to namespaces, e.g. namespace-uri-from-QName(). But I'm not sure they improve on the above for what you want.

这篇关于为什么没有名称空间限定节点的XPath语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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