Xml 命名空间破坏了我的 xpath! [英] Xml Namespace breaking my xpath!
问题描述
我有以下 XML:
<List xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<Fields>
<Field>
</Field>
</Fields>
</List>
这是从 SharePoint 网络服务返回的精简版 XML.我还有以下 xPath:
This is a slimmed down version of XML being returned from a SharePoint web service. I also have the following xPath:
/List/Fields/Field
当我从我的 XML 中删除 xmlns
时,xPath 工作正常.当它在那里时,我的 xPath 什么也没找到.我应该对 xPath 做一些不同的事情吗?修改 XML 不是一个选项.
When I remove the xmlns
from my XML the xPath works fine. When it's in there my xPath finds nothing. Is there something I should be doing differently with my xPath? Modifying the XML is not an option.
推荐答案
我还有以下 xPath:
I also have the following xPath:
/List/Fields/Field
当我从我的 XML 中删除 xmlns 时xPath 工作正常.当它在在那里我的 xPath 什么也没找到
When I remove the xmlns from my XML the xPath works fine. When it's in there my xPath finds nothing
如果不能注册命名空间绑定也不能使用(假设注册的前缀是x"):
If you cannot register a namespace binding and cannot use (assuming the registered prefix is "x"):
/x:List/x:Fields/x:Field
那么还有一种方法:
/*[name()='List']/*[name()='Fields']/*[name()='Field']
这篇关于Xml 命名空间破坏了我的 xpath!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!