Export (0) Print
Expand All

XmlSchemaComplexContent Class

Class that represents the complex content model for complex types. Contains extensions or restrictions on a complex type that has mixed content or elements only. Represents the World Wide Web Consortium (W3C) complexContent element.

For a list of all members of this type, see XmlSchemaComplexContent Members.

System.Object
   System.Xml.Schema.XmlSchemaObject
      System.Xml.Schema.XmlSchemaAnnotated
         System.Xml.Schema.XmlSchemaContentModel
            System.Xml.Schema.XmlSchemaComplexContent

[Visual Basic]
Public Class XmlSchemaComplexContent
   Inherits XmlSchemaContentModel
[C#]
public class XmlSchemaComplexContent : XmlSchemaContentModel
[C++]
public __gc class XmlSchemaComplexContent : public
   XmlSchemaContentModel
[JScript]
public class XmlSchemaComplexContent extends XmlSchemaContentModel

Thread Safety

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

Example

[Visual Basic, C#, C++] The following example creates a complexContent element.

[Visual Basic] 
Option Strict
Option Explicit

Imports System
Imports System.Xml
Imports System.Xml.Schema

Class XMLSchemaExamples
    
    Public Shared Sub Main()
        Dim schema As New XmlSchema()
        
        ' <xs:complexType name="address">
        Dim address As New XmlSchemaComplexType()
        schema.Items.Add(address)
        address.Name = "address"
        
        ' <xs:sequence>
        Dim sequence As New XmlSchemaSequence()
        address.Particle = sequence
        
        ' <xs:element name="name"   type="xs:string"/>
        Dim elementName As New XmlSchemaElement()
        sequence.Items.Add(elementName)
        elementName.Name = "name"
        elementName.SchemaTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
        
        ' <xs:element name="street"   type="xs:string"/>
        Dim elementStreet As New XmlSchemaElement()
        sequence.Items.Add(elementStreet)
        elementStreet.Name = "street"
        elementStreet.SchemaTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
        
        ' <xs:element name="city"   type="xs:string"/>
        Dim elementCity As New XmlSchemaElement()
        sequence.Items.Add(elementCity)
        elementCity.Name = "city"
        elementCity.SchemaTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
        
        ' <xs:complexType name="USAddress">
        Dim USAddress As New XmlSchemaComplexType()
        schema.Items.Add(USAddress)
        USAddress.Name = "USAddress"
        
        ' <xs:complexContent>
        Dim complexContent As New XmlSchemaComplexContent()
        USAddress.ContentModel = complexContent
        
        ' <xs:extension base="address">
        Dim extensionAddress As New XmlSchemaComplexContentExtension()
        complexContent.Content = extensionAddress
        extensionAddress.BaseTypeName = New XmlQualifiedName("address")
        
        ' <xs:sequence>
        Dim sequence2 As New XmlSchemaSequence()
        extensionAddress.Particle = sequence2
        
        ' <xs:element name="state" type="xs:string"/>
        Dim elementUSState As New XmlSchemaElement()
        sequence2.Items.Add(elementUSState)
        elementUSState.Name = "state"
        elementUSState.SchemaTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
        
        
        ' <xs:element name="zipcode" type="xs:positiveInteger"/>
        Dim elementZipcode As New XmlSchemaElement()
        sequence2.Items.Add(elementZipcode)
        elementZipcode.Name = "zipcode"
        elementZipcode.SchemaTypeName = New XmlQualifiedName("positiveInteger", "http://www.w3.org/2001/XMLSchema")
        
        schema.Compile(AddressOf ValidationCallbackOne)
        Dim nsmgr As New XmlNamespaceManager(New NameTable())
        nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema")
        schema.Write(Console.Out, nsmgr)
    End Sub 'Main
    
    
    Public Shared Sub ValidationCallbackOne(sender As Object, args As ValidationEventArgs)

        Console.WriteLine(args.Message)
    End Sub 'ValidationCallbackOne
End Class 'XMLSchemaExamples

[C#] 
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();
        schema.Items.Add(address);
        address.Name = "address";
        
        // <xs:sequence>
        XmlSchemaSequence sequence = new XmlSchemaSequence();
        address.Particle = sequence;
        
        // <xs:element name="name"   type="xs:string"/>
        XmlSchemaElement elementName = new XmlSchemaElement();
        sequence.Items.Add(elementName);
        elementName.Name = "name";
        elementName.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
        
        // <xs:element name="street"   type="xs:string"/>
        XmlSchemaElement elementStreet = new XmlSchemaElement();
        sequence.Items.Add(elementStreet);
        elementStreet.Name = "street";
        elementStreet.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
        
        // <xs:element name="city"   type="xs:string"/>
        XmlSchemaElement elementCity = new XmlSchemaElement();
        sequence.Items.Add(elementCity);
        elementCity.Name = "city";
        elementCity.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
        
        // <xs:complexType name="USAddress">
        XmlSchemaComplexType USAddress = new XmlSchemaComplexType();
        schema.Items.Add(USAddress);
        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();
        sequence2.Items.Add(elementUSState);
        elementUSState.Name = "state";
        elementUSState.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

        
        // <xs:element name="zipcode" type="xs:positiveInteger"/>
        XmlSchemaElement elementZipcode = new XmlSchemaElement();
        sequence2.Items.Add(elementZipcode);
        elementZipcode.Name = "zipcode";
        elementZipcode.SchemaTypeName = new XmlQualifiedName("positiveInteger", "http://www.w3.org/2001/XMLSchema");
        
        schema.Compile(new ValidationEventHandler(ValidationCallbackOne));
        XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
        nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
        schema.Write(Console.Out, nsmgr);
    }

    public static void ValidationCallbackOne(object sender, ValidationEventArgs args) {

        Console.WriteLine(args.Message);
    }
}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;  
using namespace System::Xml::Schema;

__gc class XMLSchemaExamples {
public:
    static void main() {
 
        XmlSchema* schema = new XmlSchema();

        // <xs:complexType name="address">
        XmlSchemaComplexType* address = new XmlSchemaComplexType();
        schema->Items->Add(address);
        address->Name = S"address";
        
        // <xs:sequence>
        XmlSchemaSequence* sequence = new XmlSchemaSequence();
        address->Particle = sequence;
        
        // <xs:element name="name"   type="xs:string"/>
        XmlSchemaElement* elementName = new XmlSchemaElement();
        sequence->Items->Add(elementName);
        elementName->Name = S"name";
        elementName->SchemaTypeName = new XmlQualifiedName(S"string", S"http://www.w3.org/2001/XMLSchema");
        
        // <xs:element name="street"   type="xs:string"/>
        XmlSchemaElement* elementStreet = new XmlSchemaElement();
        sequence->Items->Add(elementStreet);
        elementStreet->Name = S"street";
        elementStreet->SchemaTypeName = new XmlQualifiedName(S"string", S"http://www.w3.org/2001/XMLSchema");
        
        // <xs:element name="city"   type="xs:string"/>
        XmlSchemaElement* elementCity = new XmlSchemaElement();
        sequence->Items->Add(elementCity);
        elementCity->Name = S"city";
        elementCity->SchemaTypeName = new XmlQualifiedName(S"string", S"http://www.w3.org/2001/XMLSchema");
        
        // <xs:complexType name="USAddress">
        XmlSchemaComplexType* USAddress = new XmlSchemaComplexType();
        schema->Items->Add(USAddress);
        USAddress->Name = S"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(S"address");
        
        // <xs:sequence>
        XmlSchemaSequence* sequence2 = new XmlSchemaSequence();
        extensionAddress->Particle = sequence2;
        
        // <xs:element name="state" type="xs:string"/>
        XmlSchemaElement* elementUSState = new XmlSchemaElement();
        sequence2->Items->Add(elementUSState);
        elementUSState->Name = S"state";
        elementUSState->SchemaTypeName = new XmlQualifiedName(S"string", S"http://www.w3.org/2001/XMLSchema");

        
        // <xs:element name="zipcode" type="xs:positiveInteger"/>
        XmlSchemaElement* elementZipcode = new XmlSchemaElement();
        sequence2->Items->Add(elementZipcode);
        elementZipcode->Name = S"zipcode";
        elementZipcode->SchemaTypeName = new XmlQualifiedName(S"positiveInteger", S"http://www.w3.org/2001/XMLSchema");
        
        schema->Compile(new ValidationEventHandler(0, ValidationCallbackOne));
        XmlNamespaceManager* nsmgr = new XmlNamespaceManager(new NameTable());
        nsmgr->AddNamespace(S"xs", S"http://www.w3.org/2001/XMLSchema");
        schema->Write(Console::Out,nsmgr);
    }

    static void ValidationCallbackOne(Object* /*sender*/, ValidationEventArgs* args) {

        Console::WriteLine(args->Message);
    }
};

int main()
{
    XMLSchemaExamples::main();
}

[Visual Basic, C#, C++] The following XML file is generated for the preceding code example.

<?xml version="1.0" encoding="IBM437"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="address">
        <xs:sequence>
            <xs:element name="name"   type="xs:string"/>
            <xs:element name="street" type="xs:string"/>
            <xs:element name="city"   type="xs:string"/>
        </xs:sequence>
    </xs:complexType>

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Xml.Schema

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

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

See Also

XmlSchemaComplexContent Members | System.Xml.Schema Namespace

Show:
© 2015 Microsoft