Deserialize a XML fragment to class that has been generated by xsd.exe

sitsequat

New Member
I have a xml file that I want to read it and then interpret and convert to respective classes that were generated from xsd tool. Here are the steps which I am trying:[*]I created a XSD file.[*]Converted the respective xsd file into respective set of classes.[*]I made some xml files through same set of classes (from step 2) and xmlserializer.[*]Now I am reading back from those xml files and I wan't to convert it into classes (generated from step2)I am pasting the code I have worked till now, I seem to get an exception when I am deserializing, {"There is an error in XML document (0, 0)."}\[code\] var doc = XDocument.Load(filePath); var query2 = from b in doc.Root.Descendants() select b; foreach (var item in query2) { switch (item.Name.LocalName) { case "SomeStringValue": XmlSerializer srz = new XmlSerializer(typeof(SomeClassGeneratedfromXSD)); var writer=item.CreateReader(); parameterFromFile.SomeProperty = (SomeClassGeneratedfromXSD)srz.Deserialize(writer); //srz.Deserialize(item); break;\[/code\]I am pasting a snippet of what my xsd looked like:\[code\]<xs:complexType name="Parameters"><xs:all> <xs:element name="A"> <xs:complexType> <xs:simpleContent> <xs:extension base="mstns:Restricted8CharString"> <xs:attribute name="Caption" use="required" fixed="Caption for A"> <xs:simpleType> <xs:restriction base="xs:string"></xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="ActionWhenMaxReached" use="required"> <xs:simpleType> <xs:restriction base="xs:short"> <xs:pattern value="http://stackoverflow.com/questions/15717693/[1-3]"></xs:pattern> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="Expression" type="xs:string" default="0" /> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> <xs:element name="B"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:short"> <xs:attribute name="Caption" use="prohibited"> <xs:simpleType> <xs:restriction base="xs:string"></xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="ActionWhenMaxReached" use="required"> <xs:simpleType> <xs:restriction base="xs:short"> <xs:pattern value="http://stackoverflow.com/questions/15717693/[1-3]"></xs:pattern> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="Expression" type="xs:string" default="0" /> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> </xs:all> </xs:complexType>\[/code\]
 
Back
Top