【发布时间】:2013-01-03 14:28:58
【问题描述】:
我正在从用户指定的 xml 架构生成一个空的 xml,但我对属性上的命名空间声明感到困惑。
例如对于这个架构;
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://tempuri.org/Product"
targetNamespace="http://tempuri.org/Product">
<xs:complexType name="ProductType">
<xs:sequence>
</xs:sequence>
<xs:attribute name="Id" type="xs:string" />
<xs:attribute name="Name" type="xs:string" />
</xs:complexType>
<xs:element name="Product" type="ProductType" />
</xs:schema>
我已经生成了这个;
<root>
<Product xmlns="http://tempuri.org/Product"
xmlns:ns1="http://tempuri.org/Product"
ns1:Id="1"
ns1:Name="2" />
</root>
但视觉工作室生成这个;
<root>
<Product xmlns="http://tempuri.org/Product"
Id="1"
Name="2" />
</root>
哪一个是正确的?
更新 1:
无论 xml 模式 form 属性设置为什么,如果我在 XML DOM 中加载生成的 xml,Name 属性 NamespaceURI 始终为空字符串。 (虽然产品有命名空间)
我正在对这些属性执行 xpath 查询,我无法决定是始终使用命名空间前缀还是假设它始终与父元素的命名空间相同。
示例差异;
/*/ns1:Product/@Id
/*/ns1:Product/ns1:@Id
什么是命名空间属性语法的常见用例(合格?,不合格?)不知道架构?
【问题讨论】: