System.Xml.Schema.XmlSchemaComplexType Class

Assembly: System.Xml.dll
Namespace: System.Xml.Schema
Summary
Class for complex types. Defines a complex type that determines the set of attributes and content of an element. Represents the World Wide Web Consortium (W3C) complexType element.
C# Syntax:
public class XmlSchemaComplexType : XmlSchemaType
Remarks
An element can be declared with a type attribute that refers to a complexType element that defines the structure, content, and attributes of that element.
Example
The following example creates a complexType element.
using System;
using System.Xml;  
using System.Xml.Schema;

class XMLSchemaExamples {
	public static void Main() {
 
		XmlSchema schema = new XmlSchema();

		// <xs:element name="stringElementWithAnyAttribute">
		XmlSchemaElement element = new XmlSchemaElement();
		schema.Items.Add(element);
		element.Name = "stringElementWithAnyAttribute";
		
		// <xs:complexType>
		XmlSchemaComplexType complexType = new XmlSchemaComplexType();
		element.SchemaType = complexType;
		
        // <xs:simpleContent>
		XmlSchemaSimpleContent simpleContent = new XmlSchemaSimpleContent();
		complexType.ContentModel = simpleContent;
		
		// <extension base= "xs:string">
		XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension();
		simpleContent.Content = extension;
		extension.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
		
		// <xs:anyAttribute namespace="##targetNamespace"/>
		XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();
		extension.AnyAttribute = anyAttribute;
		anyAttribute.Namespace = "##targetNamespace";
 
        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);
    }
}

    

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

<?xml version="1.0" encoding="IBM437"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<xs:element name="stringElementWithAnyAttribute">
		<xs:complexType>
			<xs:simpleContent>
				<xs:extension base="xs:string">
					<xs:anyAttribute namespace="##targetNamespace"/>
				</xs:extension>
			</xs:simpleContent>
		</xs:complexType>
	</xs:element>
</xs:schema>

    
See also:
System.Xml.Schema Namespace

System.Xml.Schema.XmlSchemaComplexType Member List:

Public Constructors
ctor #1 Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Used to create a complexType element.
Public Properties
Annotation
(inherited from System.Xml.Schema.XmlSchemaAnnotated)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Annotation


Gets or sets the annotation property.
AnyAttribute Read-write

Gets or sets the value for the XmlSchemaAnyAttribute component of the complex type.
Attributes Read-only

Gets the collection of attributes for the complex type.
AttributeUses Read-only

Gets the collection of all the attributes from this complex type and its base types which holds the post-compilation value of the AttributeUses property.
AttributeWildcard Read-only

Gets the anyAttribute element from this complex type and its base types which holds the post-compilation value of the AttributeWildcard property.
BaseSchemaType
(inherited from System.Xml.Schema.XmlSchemaType)
Read-only

See base class member description: System.Xml.Schema.XmlSchemaType.BaseSchemaType


Gets the object of the simpleType element or complexType element. This is a post-schema-validation-infoset variable.
Block Read-write

Gets or sets the block attribute.
BlockResolved Read-only

Gets the value after the type has been compiled to the post-schema-validation infoset. This value indicates how the type is enforced when xsi:type is used in the instance document.
ContentModel Read-write

Gets or sets the content model type.
ContentType Read-only

Gets the content model of the complex type which holds the post-compilation value.
ContentTypeParticle Read-only

Gets the particle which holds the post-compilation value of the ContentTypeParticle property. This ContentTypeParticle is determined after the content models of the most derived types and the base complex type have been resolved according to the rules defined in the World Wide Web Consortium (W3C) XML Schema definition language (XSD) specification.
Datatype
(inherited from System.Xml.Schema.XmlSchemaType)
Read-only

See base class member description: System.Xml.Schema.XmlSchemaType.Datatype


Gets the data type that holds the post-compilation value.
DerivedBy
(inherited from System.Xml.Schema.XmlSchemaType)
Read-only

See base class member description: System.Xml.Schema.XmlSchemaType.DerivedBy


When overridden in a derived class, this property gets information that indicates how this element has been derived from a base type. This property holds the post-compilation value.
Final
(inherited from System.Xml.Schema.XmlSchemaType)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaType.Final


Gets or sets the final property to indicate that no further derivations are allowed.
FinalResolved
(inherited from System.Xml.Schema.XmlSchemaType)
Read-only

See base class member description: System.Xml.Schema.XmlSchemaType.FinalResolved


Gets the post-compilation value of the Final property that holds the post-compilation value of the Final property.
Id
(inherited from System.Xml.Schema.XmlSchemaAnnotated)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Id


Gets or sets the string id.
IsAbstract Read-write

Gets or sets the information that determines if the complexType element can be used in the instance document.
IsMixed Read-write

Overridden:
Gets or sets information that determines if the complex type has a mixed content model (markup within the content).
LineNumber
(inherited from System.Xml.Schema.XmlSchemaObject)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaObject.LineNumber


Gets or sets the line number in the file to which the schema element refers.
LinePosition
(inherited from System.Xml.Schema.XmlSchemaObject)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaObject.LinePosition


Gets or sets the line position in the file to which the schema element refers.
Name
(inherited from System.Xml.Schema.XmlSchemaType)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaType.Name


Gets or sets the name of the type.
Namespaces
(inherited from System.Xml.Schema.XmlSchemaObject)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaObject.Namespaces


Particle Read-write

Gets or sets the compositor type as one of the XmlSchemaGroupRef, XmlSchemaChoice, XmlSchemaAll, or XmlSchemaSequence classes.
QualifiedName
(inherited from System.Xml.Schema.XmlSchemaType)
Read-only

See base class member description: System.Xml.Schema.XmlSchemaType.QualifiedName


Gets the qualified name for the type built from the Name attribute of this type. This holds the post-compilation value.
SourceUri
(inherited from System.Xml.Schema.XmlSchemaObject)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaObject.SourceUri


Gets or sets the source location for the file that loaded the schema.
UnhandledAttributes
(inherited from System.Xml.Schema.XmlSchemaAnnotated)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaAnnotated.UnhandledAttributes


Gets or sets the qualified attributes that do not belong to the schema target namespace.
Public Methods
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Xml.Schema.XmlSchemaComplexType Member Details

ctor #1
Summary
Used to create a complexType element.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public XmlSchemaComplexType();

Return to top


Property: Annotation (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Annotation

Summary
Gets or sets the annotation property.
C# Syntax:
public XmlSchemaAnnotation Annotation {get; set;}

Return to top


Property: AnyAttribute (read-write)
Summary
Gets or sets the value for the XmlSchemaAnyAttribute component of the complex type.
C# Syntax:
public XmlSchemaAnyAttribute AnyAttribute {get; set;}
Remarks
If this property is not null, the complex type can contain any attributes from the namespaces specified in the XmlSchemaAnyAttribute.

Return to top


Property: Attributes (read-only)
Summary
Gets the collection of attributes for the complex type.
C# Syntax:
public XmlSchemaObjectCollection Attributes {get;}

Return to top


Property: AttributeUses (read-only)
Summary
Gets the collection of all the attributes from this complex type and its base types which holds the post-compilation value of the AttributeUses property.
C# Syntax:
public XmlSchemaObjectTable AttributeUses {get;}
Remarks
For example, a combination of all the attributes from the Attributes property from each type in the hierarchy.

The value of this property is read-only. This property has the value after the schema has been successfully compiled to determine the complete attribute set that is allowed in an instance document.

Return to top


Property: AttributeWildcard (read-only)
Summary
Gets the anyAttribute element from this complex type and its base types which holds the post-compilation value of the AttributeWildcard property.
C# Syntax:
public XmlSchemaAnyAttribute AttributeWildcard {get;}
Remarks
The value of this property is read-only. This property have values after the schema has been successfully compiled to determine the complete attribute set of the complex type. For example, it might be the anyAttribute element from one of the base types.

Return to top


Property: BaseSchemaType (read-only)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaType.BaseSchemaType

Summary
Gets the object of the simpleType element or complexType element. This is a post-schema-validation-infoset variable.
C# Syntax:
public object BaseSchemaType {get;}
Remarks
The base value must be a QName.

Return to top


Property: Block (read-write)
Summary
Gets or sets the block attribute.
C# Syntax:
public XmlSchemaDerivationMethod Block {get; set;}
Remarks
Indicates the type of derivation.

This attribute can contain the following values:



Enum Description
None Use the derivation restriction defined by the BlockDefault property of the schema, if it exists.
Extension This element cannot be replaced by a type derived by Extension.
Restriction This element cannot be replaced by a type derived by Restriction.
All #all . This element cannot be replaced by any type regardless of derivation method.

The Substitution, List, and Union derivation methods are not supported by this property.

Return to top


Property: BlockResolved (read-only)
Summary
Gets the value after the type has been compiled to the post-schema-validation infoset. This value indicates how the type is enforced when xsi:type is used in the instance document.
C# Syntax:
public XmlSchemaDerivationMethod BlockResolved {get;}
Remarks
This value is either from the type itself or, if not defined at the type level, it is taken from the schema element. For example, if the value is restricted, only the specifically defined type can be used, not types derived from the specifically defined type.

This attribute can contain the following values:



Enum Description
None Use the derivation restriction defined by the BlockDefault property of the schema, if it exists.
Extension This element cannot be replaced by a type derived by Extension.
Restriction This element cannot be replaced by a type derived by Restriction.
All #all . This element cannot be replaced by any type regardless of derivation method.

The Substitution, List, and Union derivation methods are not supported by this property.

Return to top


Property: ContentModel (read-write)
Summary
Gets or sets the content model type.
C# Syntax:
public XmlSchemaContentModel ContentModel {get; set;}
Remarks
This is mutually exclusive with the XmlSchemaComplexType.Particle property.

Return to top


Property: ContentType (read-only)
Summary
Gets the content model of the complex type which holds the post-compilation value.
C# Syntax:
public XmlSchemaContentType ContentType {get;}
Remarks
This is the content in the post-schema validation infoset.

If the IsMixed property is set to true on the ContentModel property that has the type XmlSchemaComplexContent, the value returned is Mixed.

If the IsMixed property is false, the value is either Empty or ElementOnly.

If the type on the ContentModel property has the type XmlSchemaSimpleContent, then this value is always TextOnly.

The ContentType property must have one of the values shown in the following table.



Enum Description
TextOnly Text-only content.
Empty Empty content.
ElementOnly Element-only content.
Mixed Mixed content model.

Return to top


Property: ContentTypeParticle (read-only)
Summary
Gets the particle which holds the post-compilation value of the ContentTypeParticle property. This ContentTypeParticle is determined after the content models of the most derived types and the base complex type have been resolved according to the rules defined in the World Wide Web Consortium (W3C) XML Schema definition language (XSD) specification.
C# Syntax:
public XmlSchemaParticle ContentTypeParticle {get;}

Return to top


Property: Datatype (read-only)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaType.Datatype

Summary
Gets the data type that holds the post-compilation value.
C# Syntax:
public XmlSchemaDatatype Datatype {get;}

Return to top


Property: DerivedBy (read-only)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaType.DerivedBy

Summary
When overridden in a derived class, this property gets information that indicates how this element has been derived from a base type. This property holds the post-compilation value.
C# Syntax:
public XmlSchemaDerivationMethod DerivedBy {get;}
Remarks
The value can contain a list that is a subset of Extension, Restriction, Substitution, List, or Union. The following table shows the values that this property can contain.

Enum Description
None No derivation method specified.
Substitution Derived by Substitution.
Extension Derived by Extension.
Restriction Derived by Restriction.
List Derived by List.
Union Derived by Union.

Return to top


Property: Final (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaType.Final

Summary
Gets or sets the final property to indicate that no further derivations are allowed.
C# Syntax:
public XmlSchemaDerivationMethod Final {get; set;}
Remarks
The following table shows the values that this property can contain for simple type.

Enum Description
Empty Overrides the schema blockDefault setting allowing any derivations, by restriction, extension, or substitution to take place.
None No derivation method is specified. This is the default. Derivation rules are taken from the schema blockDefault setting.
Substitution Cannot be replaced by a type derived by Substitution.
Extension Cannot be replaced by a type derived by Extension.
Restriction Cannot be replaced by a type derived by Restriction.
All #all . Cannot be replaced by a type derived by any derivation method.

The following table shows the values that this property can contain for complex type.



Enum Description
Empty Overrides the schema blockDefault setting allowing any derivations, by restriction, extension, or substitution to take place.
None No derivation method is specified. This is the default. Derivation rules are taken from the schema blockDefault setting.
Substitution Cannot be replaced by a type derived by Substitution.
Extension Cannot be replaced by a type derived by Extension.
Restriction Cannot be replaced by a type derived by Restriction.
All #all . Cannot be replaced by a type derived by any derivation method.

Return to top


Property: FinalResolved (read-only)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaType.FinalResolved

Summary
Gets the post-compilation value of the Final property that holds the post-compilation value of the Final property.
C# Syntax:
public XmlSchemaDerivationMethod FinalResolved {get;}
Remarks
This value indicates how the type is restricted when the type is extended through restriction. If the type is marked as final, this type cannot be extended.

Return to top


Property: Id (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Id

Summary
Gets or sets the string id.
C# Syntax:
public string Id {get; set;}
Remarks
The id value must be of type ID and be unique within the document containing this element.

Optional.

Return to top


Property: IsAbstract (read-write)
Summary
Gets or sets the information that determines if the complexType element can be used in the instance document.
C# Syntax:
public bool IsAbstract {get; set;}

Return to top


Overridden Property: IsMixed (read-write)
Summary
Gets or sets information that determines if the complex type has a mixed content model (markup within the content).
C# Syntax:
public override bool IsMixed {get; set;}
Remarks
Indicates if character data can appear between the child elements of this complexType. If the simpleContent element is a child element, the mixed attribute is not allowed (false). If the complexContent element is a child element, the mixed attribute can be overridden by the mixed attribute on the complexContent element.

Return to top


Property: LineNumber (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaObject.LineNumber

Summary
Gets or sets the line number in the file to which the schema element refers.
C# Syntax:
public int LineNumber {get; set;}
Remarks
LineNumber is used to store the line number when a schema is read from a file. This is reported through XmlSchemaException for error handling.

Return to top


Property: LinePosition (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaObject.LinePosition

Summary
Gets or sets the line position in the file to which the schema element refers.
C# Syntax:
public int LinePosition {get; set;}
Remarks
This is used to store the line position when a schema is read from a file. This is reported through XmlSchemaException for error handling.

Return to top


Property: Name (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaType.Name

Summary
Gets or sets the name of the type.
C# Syntax:
public string Name {get; set;}
Remarks
The name must be an NCName (no-colon name) as defined in the World Wide Web Consortium (W3C) XML Namespaces specification. Optional. If specified, the name must be unique among all simpleType and complexType elements.

Return to top


Property: Namespaces (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaObject.Namespaces

C# Syntax:
public XmlSerializerNamespaces Namespaces {get; set;}

Return to top


Property: Particle (read-write)
Summary
Gets or sets the compositor type as one of the XmlSchemaGroupRef, XmlSchemaChoice, XmlSchemaAll, or XmlSchemaSequence classes.
C# Syntax:
public XmlSchemaParticle Particle {get; set;}
Remarks
Particles must be one of the following compositors:

Element Description
group The complex type contains the elements defined in the referenced group.
sequence The complex type contains the elements defined in the specified sequence.
choice The complex type allows one of the elements specified in the choice element.
all The complex type allows all of the elements specified in the all element to appear once or not at all.

This is mutually exclusive with the XmlSchemaComplexType.ContentModel property.

Return to top


Property: QualifiedName (read-only)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaType.QualifiedName

Summary
Gets the qualified name for the type built from the Name attribute of this type. This holds the post-compilation value.
C# Syntax:
public XmlQualifiedName QualifiedName {get;}

Return to top


Property: SourceUri (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaObject.SourceUri

Summary
Gets or sets the source location for the file that loaded the schema.
C# Syntax:
public string SourceUri {get; set;}
Remarks
Provides information for exception handling.

Return to top


Property: UnhandledAttributes (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaAnnotated.UnhandledAttributes

Summary
Gets or sets the qualified attributes that do not belong to the schema target namespace.
C# Syntax:
public XmlAttribute[] UnhandledAttributes {get; set;}

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~XmlSchemaComplexType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.