All Element Binding Support
Collapse the table of content
Expand the table of content

All Element Binding Support 

The .NET Framework provides binding support for the <all> element.

However, there is no way to specify the <all> element in code so that it will be created when generating an XML Schema document from a set of classes.

There is no way to specify the <all> element in code so that it will be created when generating an XML Schema document from a set of classes.

The <all> element provides an unordered grouping of elements. Each of the child elements can appear once or not appear at all.

When generating source code from an XML Schema document, Xsd.exe translates each child element of the <all> element into a public field. The fields appear in the same order as the child elements in the XML schema.

When generating an XML Schema document from a set of classes in an assembly, Xsd.exe uses a <sequence> element instead of an <all> element to group the child elements corresponding to the public fields. The assumption is that elements within a complex type should appear ordered, not unordered.

Do not use the order preservation feature (the /order switch on Xsd.exe) when importing schemas that contain an <all> element.

Example

Input XML Schema document:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            targetNamespace="http://example.org/" xmlns="http://example.org/" elementFormDefault="qualified">
    <xsd:element name="complexInstance" type="MyComplexType"/>
    <xsd:element name="field1" type="xsd:string"/>
    <xsd:element name="field2" type="xsd:string"/>
    <xsd:element name="field3" type="xsd:string"/>

    <xsd:complexType name="MyComplexType">
        <xsd:all>
            <xsd:element ref="field1"/>
            <xsd:element ref="field2"/>
            <xsd:element ref="field3"/>
        </xsd:all>
    </xsd:complexType>
</xsd:schema>

C# class generated from the preceding XML Schema document:

[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.org/")]
 [System.Xml.Serialization.XmlRootAttribute("complexInstance", Namespace="http://example.org/", IsNullable=false)]
public class MyComplexType {
        
    public string field1;
        
    public string field2;
        
    public string field3;
}

XML Schema complex type generated from an assembly compiled from the preceding C# source:

<xs:complexType name="MyComplexType">
    <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="1" name="field1" type="xs:string" />
        <xs:element minOccurs="0" maxOccurs="1" name="field2" type="xs:string" />
        <xs:element minOccurs="0" maxOccurs="1" name="field3" type="xs:string" />
    </xs:sequence>
</xs:complexType>
Possible Attributes Binding Support

id

The Xsd.exe utility ignores the id attribute, which is intended to provide a unique identifier.

maxOccurs

For the <all> element, any value for the maxOccurs attribute other than 1 is invalid. Xsd.exe reports an error for an invalid value.

See the MaxOccurs Attribute Binding Support attribute.

minOccurs

The Xsd.exe tool ignores the minOccurs attribute when applied to the <all> element.

See the MinOccurs Attribute Binding Support attribute.

Possible parent elements: <complexType>, <extension>, <group>, <restriction>

Possible child elements: <annotation>, <element>

Community Additions

ADD
Show:
© 2016 Microsoft