是否有可能在XPath的EX pression指定只有一次的命名空间preFIX? [英] Is it possible to specify the namespace prefix just once in a xpath expression?

查看:122
本文介绍了是否有可能在XPath的EX pression指定只有一次的命名空间preFIX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XML文件中,根元素上定义只有一个命名空间。

I have only one namespace in my XML file, defined on the root element.

<root xmlns="http://my-namespace">
    <aChild>
        <secondChild />
    ...

是否有可能避免我的XPath EX pression每个元素之前写它?
后做

xmlNamespaceManager.AddNamespace("ns", "http://my-namespace");

我有写

xml.SelectNodes("ns:root/ns:aChild/ns:secondChild", xmlNamespaceManager);

那将是更容易做到这

And it would be much easier to do just

xml.SelectNodes("ns:root/aChild/secondChild", xmlNamespaceManager);

我有谁送的XPath EX pressions到XML developpers,但他们不一定知道preFIX或命名空间,他们只知道自己要访问根/ aChild / secondChild

感谢你。

推荐答案

不幸的是直观,因为它似乎,有没有简单的方法做定义的XPath默认的命名空间。没有命名空间声明的XPath名称绑定到命名空间,而不是URI分配到默认名称空间。

Unfortunately as intuitive as it seems, there's no easy way do define the default namespace in XPath. An XPath name without a namespace declaration binds to the null namespace, rather than the URI assigned to the default namespace.

这是在 XPath的默认命名空间处理和的容易的事情应该很容易

这篇关于是否有可能在XPath的EX pression指定只有一次的命名空间preFIX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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