我从用户指定的XML模式生成一个空的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>
但是visual studio产生这个;
<root>
<Product xmlns="http://tempuri.org/Product"
Id="1"
Name="2" />
</root>
哪一个是正确的?
更新1:
无论XML架构形式属性设置为,如果我加载XML DOM生成的XML,名称属性的namespaceURI总是空的字符串。 (虽然产品有命名空间)
我对这些属性执行xpath查询,我无法决定应该始终使用命名空间前缀还是假定它始终与父元素的命名空间相同。
示例差异;
/*/ns1:Product/@Id
/*/ns1:Product/ns1:@Id
什么是命名空间属性语法(限定?,不合格?)的常见用例而不知道模式?