Create a list for each element, instead of a single List of objects

Nov 26, 2014 at 4:13 AM
Hi all,

Brand new to xsd@Code, and fairly new to XML serialization/deserialization in general. I'm working on a project where I need to convert a rather large xsd into a set of C# classes. xsd2Code created the classes wonderfully, and I have setup nearly to where I'd like it to be after fiddling with the settings.

The one thing that I'm unable to figure out how to do (if it can even be done) is to generate separate classes for each possible element within one element. xsd@Code generates a single List<object> Items for all possible elements by default. Is there a setting that would give me what I want?

So, for example, I would have something similar to the below generated (along with the initializers in the constructor):
        [XmlElementAttribute("foo", typeof(foo))]
        public List<condition> Foos{ get; set; }
        [XmlElementAttribute("bar", typeof(bar))]
        public List<navigation> Bars{ get; set; }
        [XmlElementAttribute("fooBar", typeof(fooBar))]
        public List<presentation> FooBars{ get; set; }

       /// <summary>
        /// FooBarParent class constructor
        /// </summary>
        public FooBarParent()
        {
            Foos= new List<foo>();
            Navigations = new List<bar>();
            FooBars= new List<fooBar>();
         }
instead of them all being placed into the single list of generic objects, like the below.
        [XmlElementAttribute("foo", typeof(foo))]
        [XmlElementAttribute("bar", typeof(bar))]
        [XmlElementAttribute("fooBar", typeof(fooBar))]
        public List<object> Items{ get; set; }

       /// <summary>
        /// FooBarParent class constructor
        /// </summary>
        public FooBarParent()
        {
            Items= new List<object>();
         }
I can go and alter the code, but there are a few thousand different element types I need to deal with, so I'd rather have something auto generated if possible.

Thanks!
Mar 16, 2015 at 11:41 AM
I'm having the exact same problem using the code below from my xsd:
    <xs:complexType name="behavior">
        <xs:sequence minOccurs="1" maxOccurs="unbounded">
          <xs:element name="event" type="Event" />
          <xs:element name="data1" type="info" />
          <xs:element name="data2" type="info" />
        </xs:sequence>
    </xs:complexType>
When I use one of my PC's with xsd2code 3.4 to build this code it generates 3 separate lists for event, data1 and data2.

When I use a different PC with xsd2code 3.4 it generates a single list that can contain all three data types.

How can I specify the use of the first behavior only?

Regards, Mike!