Search code examples
c#xmlxsdxsd2code

xsd2code element gets replaced by list


i have the following code in my *.xsd file

  <xs:element name="node">
    <xs:complexType>
      <xs:sequence>
        ...
      </xs:sequence>
      <xs:attribute name="id" type="xs:string" use="required"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="foo">
    <xs:complexType>
      <xs:sequence>
        <!-- this should be lists of bar and baz and NOT of node -->
        <xs:element ref="bar" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element ref="baz" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="bar">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="node" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="baz">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="node" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

but when i gernerate this code with xsd2code i get some strange output where the bar and baz properties in foo are lists of nodes. I need bar and baz to be classes that hold a list of nodes. How can i do this ?

public partial class foo { // generated class

    private List<node> barField; // ?!

    private List<node> bazField; // ?!

    // ...
}

Solution

  • found a solution for my problem. I just had to set mixed="true". Here is the code:

      ...
      <xs:element name="bar">
        <xs:complexType mixed="1">
          <xs:sequence>
            <xs:element ref="node" minOccurs="0" maxOccurs="unbounded"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      ...
    
    
    public partial class foo { // generated class
    
            private List<bar> barField;
    
            private List<baz> bazField;
    
            // ...
    }