【发布时间】:2010-05-16 00:07:54
【问题描述】:
我有以下提供给我的 XML,但我无法更改:
<Parent>
<Settings Version="1234" xmlns="urn:schemas-stuff-com"/>
</Parent>
我正在尝试使用 XPath 检索“版本”属性值。由于 xmlns 的定义没有别名,因此它会自动将该 xmlns 分配给 Settings 节点。当我将此 XML 读入 XMLDocument 并查看 Settings 节点的 namespaceURI 值时,它被设置为“urn:schemas-stuff-com”。
我试过了:
//Parent/Settings/@Version - 返回 Null
//Parent/urn:schemas-stuff-com:Settings/@Version - 无效语法
【问题讨论】:
-
好问题 (+1)。有关不依赖于特定实现或特定编程语言的解决方案,请参阅我的答案。 :)