public class XmlSchemaComplexContentRestriction : XmlSchemaContent
|
using System; using System.Xml; using System.Xml.Schema; class XMLSchemaExamples { public static void Main() { XmlSchema schema = new XmlSchema(); // <xs:complexType name="phoneNumber"> XmlSchemaComplexType phoneNumber = new XmlSchemaComplexType(); phoneNumber.Name = "phoneNumber"; // <xs:sequence> XmlSchemaSequence phoneNumberSequence = new XmlSchemaSequence(); // <xs:element name="areaCode"/> XmlSchemaElement areaCode1 = new XmlSchemaElement(); areaCode1.MinOccurs = 0; areaCode1.MaxOccursString = "1"; areaCode1.Name = "areaCode"; phoneNumberSequence.Items.Add(areaCode1); // <xs:element name="prefix"/> XmlSchemaElement prefix1 = new XmlSchemaElement(); prefix1.MinOccurs = 1; prefix1.MaxOccursString = "1"; prefix1.Name = "prefix"; phoneNumberSequence.Items.Add(prefix1); // <xs:element name="number"/> XmlSchemaElement number1 = 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"> XmlSchemaComplexType localPhoneNumber = new XmlSchemaComplexType(); localPhoneNumber.Name = "localPhoneNumber"; // <xs:complexContent> XmlSchemaComplexContent complexContent = new XmlSchemaComplexContent(); // <xs:restriction base="phoneNumber"> XmlSchemaComplexContentRestriction restriction = new XmlSchemaComplexContentRestriction(); restriction.BaseTypeName = new XmlQualifiedName("phoneNumber", ""); // <xs:sequence> XmlSchemaSequence sequence2 = new XmlSchemaSequence(); // <xs:element name="areaCode" minOccurs="0"/> XmlSchemaElement areaCode2 = new XmlSchemaElement(); areaCode2.MinOccurs = 0; areaCode2.MaxOccursString = "1"; areaCode2.Name = "areaCode"; sequence2.Items.Add(areaCode2); // <xs:element name="prefix"/> XmlSchemaElement prefix2 = new XmlSchemaElement(); prefix2.MinOccurs = 1; prefix2.MaxOccursString = "1"; prefix2.Name = "prefix"; sequence2.Items.Add(prefix2); // <xs:element name="number"/> XmlSchemaElement number2 = 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); 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 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>
ctor #1 | Default constructor. This constructor is called by derived class constructors to initialize state in this type. |
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 XmlSchemaAnyAttribute component of the complex content model. |
Attributes | Read-only Gets the collection of attributes for the complex type. Contains the XmlSchemaAttribute and XmlSchemaAttributeGroupRef elements. |
BaseTypeName | Read-write Gets or sets the name of a complex type from which this type is derived by restriction. |
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. |
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. |
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 one of the XmlSchemaGroupRef, XmlSchemaChoice, XmlSchemaAll, or XmlSchemaSequence classes. |
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. |
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. |
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:
public XmlSchemaComplexContentRestriction(); |
public XmlSchemaAnnotation Annotation {get; set;}
|
public XmlSchemaAnyAttribute AnyAttribute {get; set;}
|
public XmlSchemaObjectCollection Attributes {get;}
|
public XmlQualifiedName BaseTypeName {get; set;}
|
public string Id {get; set;}
|
Optional.
public int LineNumber {get; set;}
|
public int LinePosition {get; set;}
|
public XmlSerializerNamespaces Namespaces {get; set;}
|
public XmlSchemaParticle Particle {get; set;}
|
public string SourceUri {get; set;}
|
public XmlAttribute[] UnhandledAttributes {get; set;}
|
~XmlSchemaComplexContentRestriction(); |
public virtual int GetHashCode(); |
public Type GetType(); |
protected object MemberwiseClone(); |
public virtual string ToString(); |