我從用戶指定的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
什麼是命名空間屬性語法(限定?,不合格?)的常見用例而不知道模式?