给定以下 XML 标记:
<root xmlns="Demo">
<child name="foo"/>
</root>
和一个XPathNavigator定位在<child>元素上,
string withNs = navigator.GetAttribute("name", navigator.NamespaceURI);
string withoutNs = navigator.GetAttribute("name", "");
产生奇怪的结果:withNs是空的,withoutNs包含foo.
这是为什么?我本来希望它会反过来,因为name属性必须Demo像child元素一样位于命名空间中。
MSDN 文档没有提到 pass 的任何神奇含义namespaceURI="",所以我假设您必须传递属性的真实命名空间 URI。