XmlSchemaComplexContentRestriction Class
Represents the restriction element from XML Schema as specified by the World Wide Web Consortium (W3C). 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.
Assembly: System.Xml (in System.Xml.dll)
System.Xml.Schema::XmlSchemaObject
System.Xml.Schema::XmlSchemaAnnotated
System.Xml.Schema::XmlSchemaContent
System.Xml.Schema::XmlSchemaComplexContentRestriction
| 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 the default hash function. (Inherited from Object.) |
![]() | GetType() | |
![]() | MemberwiseClone() | |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
The following example creates a complexContent element extended by restriction.
#using <mscorlib.dll> #using <System.Xml.dll> using namespace System; using namespace System::Xml; using namespace System::Xml::Schema; class XmlSchemaExamples { public: static void Main() { XmlSchema^ schema = gcnew XmlSchema(); // <xs:complexType name="phoneNumber"> XmlSchemaComplexType^ phoneNumber = gcnew XmlSchemaComplexType(); phoneNumber->Name = "phoneNumber"; // <xs:sequence> XmlSchemaSequence^ phoneNumberSequence = gcnew XmlSchemaSequence(); // <xs:element name="areaCode"/> XmlSchemaElement^ areaCode1 = gcnew XmlSchemaElement(); areaCode1->MinOccurs = 0; areaCode1->MaxOccursString = "1"; areaCode1->Name = "areaCode"; phoneNumberSequence->Items->Add(areaCode1); // <xs:element name="prefix"/> XmlSchemaElement^ prefix1 = gcnew XmlSchemaElement(); prefix1->MinOccurs = 1; prefix1->MaxOccursString = "1"; prefix1->Name = "prefix"; phoneNumberSequence->Items->Add(prefix1); // <xs:element name="number"/> XmlSchemaElement^ number1 = gcnew 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"> XmlSchemaComplexType^ localPhoneNumber = gcnew XmlSchemaComplexType(); localPhoneNumber->Name = "localPhoneNumber"; // <xs:complexContent> XmlSchemaComplexContent^ complexContent = gcnew XmlSchemaComplexContent(); // <xs:restriction base="phoneNumber"> XmlSchemaComplexContentRestriction^ restriction = gcnew XmlSchemaComplexContentRestriction(); restriction->BaseTypeName = gcnew XmlQualifiedName("phoneNumber", ""); // <xs:sequence> XmlSchemaSequence^ sequence2 = gcnew XmlSchemaSequence(); // <xs:element name="areaCode" minOccurs="0"/> XmlSchemaElement^ areaCode2 = gcnew XmlSchemaElement(); areaCode2->MinOccurs = 0; areaCode2->MaxOccursString = "1"; areaCode2->Name = "areaCode"; sequence2->Items->Add(areaCode2); // <xs:element name="prefix"/> XmlSchemaElement^ prefix2 = gcnew XmlSchemaElement(); prefix2->MinOccurs = 1; prefix2->MaxOccursString = "1"; prefix2->Name = "prefix"; sequence2->Items->Add(prefix2); // <xs:element name="number"/> XmlSchemaElement^ number2 = gcnew 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); XmlSchemaSet^ schemaSet = gcnew XmlSchemaSet(); schemaSet->ValidationEventHandler += gcnew ValidationEventHandler(ValidationCallbackOne); schemaSet->Add(schema); schemaSet->Compile(); XmlSchema^ compiledSchema; for each (XmlSchema^ schema1 in schemaSet->Schemas()) { compiledSchema = schema1; } XmlNamespaceManager^ nsmgr = gcnew XmlNamespaceManager(gcnew NameTable()); nsmgr->AddNamespace("xs", "http://www.w3.org/2001/XMLSchema"); compiledSchema->Write(Console::Out, nsmgr); } static void ValidationCallbackOne(Object^ sender, ValidationEventArgs^ args) { Console::WriteLine(args->Message); } }; int main() { XmlSchemaExamples::Main(); return 0; };
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>
Available since 1.1
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


