I serialize and deserialize .net objects using the XmlSerializer class without any problems, however now we need someone else to look at this data in order to do some analysis on it.
To help with this, we created an XSD based on our class: xsd.exe / t: DataClass Assembly.exe
The start of the XSD looks like this:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="DataClass" nillable="true" type="DataClass" />
<xs:complexType name="DataClass">
<xs:complexContent mixed="false">
<xs:extension base="BaseDataClass">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="StudyID" type="xs:string" />
<xs:element minOccurs="1" maxOccurs="1" name="Position" type="xs:int" />
<xs:element minOccurs="1" maxOccurs="1" name="IViewer" type="xs:string" />
XML is created this way (where obj is an instance of our DataClass):
Dim xs As New XmlSerializer(obj.GetType)
Dim xmlTextWriter As New XmlTextWriter(memoryStream, Encoding.UTF8)
xs.Serialize(xmlTextWriter, obj)
... which creates an XML that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<DataClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Version>SixMonthQ-E1</Version>
<IViewer xsi:nil="true" />
<Language xsi:nil="true" />
...
<StudyID>12345</StudyID>
In Bizarly, the resulting XML does not adhere to the XSD generated from the same class.
Then my question is: is there a way to tell XmlSerializer about serializing an object based on this XSD?
, :
XSD - , , .
, XmlElement, 400 .