XPath 可以用于返回节点上的命名空间吗? [英] Can XPath be used to return namespaces on nodes?
问题描述
可以使用 XPath (1.0) 返回 XML 文档中的命名空间节点吗?
Can XPath (1.0) be used to return the namespace nodes in an XML document?
注意:我不是要求具有给定名称空间的节点,而是名称空间节点本身.所以不是:
Note: I am not asking for nodes which have a given namespace, but the namespace nodes themselves. So NOT:
//node()[namespace-uri()='http://a.b']
推荐答案
如果实现了命名空间轴(Firefox/Mozilla 拒绝这样做)那么 //namespace::node()
给你所有命名空间节点.但请注意,XSLT/XPath 数据模型中的命名空间节点与 XML 文档中的命名空间声明属性不同,带有标记
If the namespace axis is implemented (Firefox/Mozilla refuses to do that) then //namespace::node()
gives you all namespace nodes. But note that namespace nodes in the XSLT/XPath data model are different from namespace declaration attributes in the XML document, with the markup
<root xmlns="http://example.com/ns">
<foo>
<bar>baz</bar>
</foo>
</root>
所有三个元素都有两个作用域命名空间节点,一个是在根元素上声明的默认节点,另一个是用于 xml
命名空间的内置节点.
all three elements each have two in scope namespace nodes, the default one declared on the root element and the built-in one for the xml
namespace.
这篇关于XPath 可以用于返回节点上的命名空间吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!