我想在編輯一些XML文件時使用Visual Studio的架構驗證。這些文件包含要讀取的序列化對象DataContractSerializer
。anyType元素的架構驗證
<?xml version="1.0" encoding="utf-8" ?>
<MyRoot xmlns="http://schemas.datacontract.org/2004/07/MyDomain"
xmlns:lib="http://schemas.datacontract.org/2004/07/MyLibrary"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<MyList xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a:anyType i:type="lib:MyObject">
<lib:Identifier>my-identifier</lib:Identifier>
<lib:MyProperty>my-property-value</lib:MyProperty>
</a:anyType>
<a:anyType i:type="lib:MyOtherObject">
<lib:Identifier>my-identifier</lib:Identifier>
<lib:MyOtherProperty>my-other-property-value</lib:MyOtherProperty>
</a:anyType>
</MyList>
</MyRoot>
我以前在Visual Studio中的「創建模式」菜單選項生成XSD文件,但編輯仍然顯示此錯誤的<a:anyType
元素:
This is an invalid xsi:type 'http://schemas.datacontract.org/2004/07/MyLibrary:MyObject'
我試圖編輯XSD文件對於「http://schemas.microsoft.com/2003/10/Serialization/Arrays」命名空間,但到目前爲止我還沒有能夠消除這個錯誤。這是XSD文件作爲Visual Studio生成它。
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/Arrays" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://schemas.datacontract.org/2004/07/MyLibrary" />
<xs:element name="anyType">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q1="http://schemas.datacontract.org/2004/07/MyLibrary" ref="q1:MyProperty" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
您是否可以包含導入的模式? http://schemas.datacontract.org/2004/07/MyLibrary – helderdarocha