This documentation is archived and is not being maintained.

XmlSchemaComplexContent Class

Represents the complexContent element from XML Schema as specified by the World Wide Web Consortium (W3C). This class represents the complex content model for complex types. It contains extensions or restrictions on a complex type that has either only elements or mixed content.

Namespace:  System.Xml.Schema
Assembly:  System.Xml (in System.Xml.dll)

public class XmlSchemaComplexContent : XmlSchemaContentModel

The following example creates a complexContent element.

using System;
using System.Xml;
using System.Xml.Schema;

class XMLSchemaExamples
    public static void Main()

        XmlSchema schema = new XmlSchema();

        // <xs:complexType name="address">
        XmlSchemaComplexType address = new XmlSchemaComplexType();
        address.Name = "address";

        // <xs:sequence>
        XmlSchemaSequence sequence = new XmlSchemaSequence();
        address.Particle = sequence;

        // <xs:element name="name"   type="xs:string"/>
        XmlSchemaElement elementName = new XmlSchemaElement();
        elementName.Name = "name";
        elementName.SchemaTypeName = new XmlQualifiedName("string", "");

        // <xs:element name="street"   type="xs:string"/>
        XmlSchemaElement elementStreet = new XmlSchemaElement();
        elementStreet.Name = "street";
        elementStreet.SchemaTypeName = new XmlQualifiedName("string", "");

        // <xs:element name="city"   type="xs:string"/>
        XmlSchemaElement elementCity = new XmlSchemaElement();
        elementCity.Name = "city";
        elementCity.SchemaTypeName = new XmlQualifiedName("string", "");

        // <xs:complexType name="USAddress">
        XmlSchemaComplexType USAddress = new XmlSchemaComplexType();
        USAddress.Name = "USAddress";

        // <xs:complexContent>
        XmlSchemaComplexContent complexContent = new XmlSchemaComplexContent();
        USAddress.ContentModel = complexContent;

        // <xs:extension base="address">
        XmlSchemaComplexContentExtension extensionAddress = new XmlSchemaComplexContentExtension();
        complexContent.Content = extensionAddress;
        extensionAddress.BaseTypeName = new XmlQualifiedName("address");

        // <xs:sequence>
        XmlSchemaSequence sequence2 = new XmlSchemaSequence();
        extensionAddress.Particle = sequence2;

        // <xs:element name="state" type="xs:string"/>
        XmlSchemaElement elementUSState = new XmlSchemaElement();
        elementUSState.Name = "state";
        elementUSState.SchemaTypeName = new XmlQualifiedName("string", "");

        // <xs:element name="zipcode" type="xs:positiveInteger"/>
        XmlSchemaElement elementZipcode = new XmlSchemaElement();
        elementZipcode.Name = "zipcode";
        elementZipcode.SchemaTypeName = new XmlQualifiedName("positiveInteger", "");

        XmlSchemaSet schemaSet = new XmlSchemaSet();
        schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne);

        XmlSchema compiledSchema = null;

        foreach (XmlSchema schema1 in schemaSet.Schemas())
            compiledSchema = schema1;

        XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
        nsmgr.AddNamespace("xs", "");
        compiledSchema.Write(Console.Out, nsmgr);

    public static void ValidationCallbackOne(object sender, ValidationEventArgs args)


The following XML file is generated for the preceding code example.

<?xml version="1.0" encoding="IBM437"?>
<xs:schema xmlns:xs="">
    <xs:complexType name="address">
            <xs:element name="name"   type="xs:string"/>
            <xs:element name="street" type="xs:string"/>
            <xs:element name="city"   type="xs:string"/>

    <xs:complexType name="USAddress">
        <xs:complexContent mixed="false">
            <xs:extension base="address">
                    <xs:element name="state" type="xs:string"/>
                    <xs:element name="zipcode" type="xs:positiveInteger"/>

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0

XNA Framework

Supported in: 3.0, 2.0, 1.0