XmlSchemaComplexContentRestriction Class
Represents the restriction element from XML Schema as specified by the . This class is for complex types with a complex content model derived by restriction. It restricts the contents of the complex type to a subset of the inherited complex type.
System.Xml.Schema.XmlSchemaObject
System.Xml.Schema.XmlSchemaAnnotated
System.Xml.Schema.XmlSchemaContent
System.Xml.Schema.XmlSchemaComplexContentRestriction
Assembly: System.Xml (in System.Xml.dll)
The XmlSchemaComplexContentRestriction type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() | XmlSchemaComplexContentRestriction | Initializes a new instance of the XmlSchemaComplexContentRestriction class. |
| Name | Description | |
|---|---|---|
![]() ![]() | Annotation | Gets or sets the annotation property. (Inherited from XmlSchemaAnnotated.) |
![]() ![]() | AnyAttribute | Gets or sets the XmlSchemaAnyAttribute component of the complex content model. |
![]() ![]() | Attributes | Gets the collection of attributes for the complex type. Contains the XmlSchemaAttribute and XmlSchemaAttributeGroupRef elements. |
![]() ![]() | BaseTypeName | Gets or sets the name of a complex type from which this type is derived by restriction. |
![]() ![]() | Id | Gets or sets the string id. (Inherited from XmlSchemaAnnotated.) |
![]() ![]() | LineNumber | Gets or sets the line number in the file to which the schema element refers. (Inherited from XmlSchemaObject.) |
![]() ![]() | LinePosition | Gets or sets the line position in the file to which the schema element refers. (Inherited from XmlSchemaObject.) |
![]() ![]() | Namespaces | Gets or sets the XmlSerializerNamespaces to use with this schema object. (Inherited from XmlSchemaObject.) |
![]() ![]() | Parent | Gets or sets the parent of this XmlSchemaObject. (Inherited from XmlSchemaObject.) |
![]() ![]() | Particle | Gets or sets one of the XmlSchemaGroupRef, XmlSchemaChoice, XmlSchemaAll, or XmlSchemaSequence classes. |
![]() ![]() | SourceUri | Gets or sets the source location for the file that loaded the schema. (Inherited from XmlSchemaObject.) |
![]() ![]() | UnhandledAttributes | Gets or sets the qualified attributes that do not belong to the current schema's target namespace. (Inherited from XmlSchemaAnnotated.) |
| Name | Description | |
|---|---|---|
![]() ![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() ![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() ![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() ![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() ![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() ![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
The following example creates a complexContent element extended by restriction.
Option Explicit On Option Strict On Imports System Imports System.Xml Imports System.Xml.Schema Class XMLSchemaExamples Public Shared Sub Main() Dim schema As New XmlSchema() ' <xs:complexType name="phoneNumber"> Dim phoneNumber As New XmlSchemaComplexType() phoneNumber.Name = "phoneNumber" ' <xs:sequence> Dim phoneNumberSequence As New XmlSchemaSequence() ' <xs:element name="areaCode"/> Dim areaCode1 As New XmlSchemaElement() areaCode1.MinOccurs = 0 areaCode1.MaxOccursString = "1" areaCode1.Name = "areaCode" phoneNumberSequence.Items.Add(areaCode1) ' <xs:element name="prefix"/> Dim prefix1 As New XmlSchemaElement() prefix1.MinOccurs = 1 prefix1.MaxOccursString = "1" prefix1.Name = "prefix" phoneNumberSequence.Items.Add(prefix1) ' <xs:element name="number"/> Dim number1 As New XmlSchemaElement() number1.MinOccurs = 1 number1.MaxOccursString = "1" number1.Name = "number" phoneNumberSequence.Items.Add(number1) phoneNumber.Particle = phoneNumberSequence schema.Items.Add(phoneNumber) ' <xs:complexType name="localPhoneNumber"> Dim localPhoneNumber As New XmlSchemaComplexType() localPhoneNumber.Name = "localPhoneNumber" ' <xs:complexContent> Dim complexContent As New XmlSchemaComplexContent() ' <xs:restriction base="phoneNumber"> Dim restriction As New XmlSchemaComplexContentRestriction() restriction.BaseTypeName = New XmlQualifiedName("phoneNumber", "") ' <xs:sequence> Dim sequence2 As New XmlSchemaSequence() ' <xs:element name="areaCode" minOccurs="0"/> Dim areaCode2 As New XmlSchemaElement() areaCode2.MinOccurs = 0 areaCode2.MaxOccursString = "1" areaCode2.Name = "areaCode" sequence2.Items.Add(areaCode2) ' <xs:element name="prefix"/> Dim prefix2 As New XmlSchemaElement() prefix2.MinOccurs = 1 prefix2.MaxOccursString = "1" prefix2.Name = "prefix" sequence2.Items.Add(prefix2) ' <xs:element name="number"/> Dim number2 As New XmlSchemaElement() number2.MinOccurs = 1 number2.MaxOccursString = "1" number2.Name = "number" sequence2.Items.Add(number2) restriction.Particle = sequence2 complexContent.Content = restriction localPhoneNumber.ContentModel = complexContent schema.Items.Add(localPhoneNumber) Dim schemaSet As New XmlSchemaSet() AddHandler schemaSet.ValidationEventHandler, AddressOf ValidationCallbackOne schemaSet.Add(schema) schemaSet.Compile() Dim compiledSchema As XmlSchema = Nothing For Each schema1 As XmlSchema In schemaSet.Schemas() compiledSchema = schema1 Next Dim nsmgr As New XmlNamespaceManager(New NameTable()) nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema") compiledSchema.Write(Console.Out, nsmgr) End Sub 'Main Public Shared Sub ValidationCallbackOne(ByVal sender As Object, ByVal args As ValidationEventArgs) Console.WriteLine(args.Message) End Sub 'ValidationCallbackOne End Class 'XMLSchemaExamples
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="phoneNumber">
<xs:sequence>
<xs:element name="areaCode" minOccurs="0" maxOccurs="1"/>
<xs:element name="prefix" minOccurs="1" maxOccurs="1"/>
<xs:element name="number" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="localPhoneNumber">
<xs:complexContent mixed="false">
<xs:restriction base="phoneNumber">
<xs:sequence>
<xs:element name="areaCode" minOccurs="0" maxOccurs="1"/>
<xs:element name="prefix" minOccurs="1" maxOccurs="1"/>
<xs:element name="number" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:schema>
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.



