FaCToR.eXh
New Member
I am rewriting an old system and I have created a schema from an XML document using xsd.exe and then generated .NET code from the xsd using xsd.exe/xsd2code. However there seems to be a flaw, possibly in the design of the original xml document or the way that it has been generated but I don't know enough about schemas to correct the problem. Here is a cleaned up sample that illustrates the problem:\[code\]<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="ABC"> <xs:complexType> <xs:all> <xs:element ref="ABC_HEADER"/> <xs:element name="BODY_A" minOccurs="0" /> <xs:element name="BODY_B" minOccurs="0" /> <xs:element name="BODY_C" minOccurs="0" /> </xs:all> </xs:complexType> </xs:element></xs:schema>\[/code\]The idea is that the ABC class is a message that contains a header and a single body element that can be of various types (I did not design this). When the generated class is serialized I get one of each of the body classes in the output XML:\[code\]<?xml version="1.0" encoding="utf-8"?><ABC> <ABC_HEADER> </ABC_HEADER> <BODY_A></BODY_A> <BODY_B></BODY_B> <BODY_C></BODY_C>\[/code\]Given that I cannot change the design and that the produced XML needs to match the legacy XML is the \[code\]<xs:all>\[/code\] choice the right way to represent this or would <\[code\]xs:sequence>\[/code\] or something else be a better choice?Alternatively, do I need to write some custom (pre)serialization code that generates the corect output?