public class XmlSchemaSequence : XmlSchemaGroupBase
|
using System; using System.Xml; using System.Xml.Schema; class XMLSchemaExamples { public static void Main() { XmlSchema schema = new XmlSchema(); // <xs:element name="thing1" type="xs:string"/> XmlSchemaElement elementThing1 = new XmlSchemaElement(); schema.Items.Add(elementThing1); elementThing1.Name = "thing1"; elementThing1.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); // <xs:element name="thing2" type="xs:string"/> XmlSchemaElement elementThing2 = new XmlSchemaElement(); schema.Items.Add(elementThing2); elementThing2.Name = "thing2"; elementThing2.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); // <xs:element name="thing3" type="xs:string"/> XmlSchemaElement elementThing3 = new XmlSchemaElement(); schema.Items.Add(elementThing3); elementThing3.Name = "thing3"; elementThing3.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); // <xs:attribute name="myAttribute" type="xs:decimal"/> XmlSchemaAttribute myAttribute = new XmlSchemaAttribute(); schema.Items.Add(myAttribute); myAttribute.Name = "myAttribute"; myAttribute.SchemaTypeName = new XmlQualifiedName("decimal", "http://www.w3.org/2001/XMLSchema"); // <xs:group name="myGroupOfThings"> XmlSchemaGroup myGroupOfThings = new XmlSchemaGroup(); schema.Items.Add(myGroupOfThings); myGroupOfThings.Name = "myGroupOfThings"; // <xs:sequence> XmlSchemaSequence sequence = new XmlSchemaSequence(); myGroupOfThings.Particle = sequence; // <xs:element ref="thing1"/> XmlSchemaElement elementThing1Ref = new XmlSchemaElement(); sequence.Items.Add(elementThing1Ref); elementThing1Ref.RefName = new XmlQualifiedName("thing1"); // <xs:element ref="thing2"/> XmlSchemaElement elementThing2Ref = new XmlSchemaElement(); sequence.Items.Add(elementThing2Ref); elementThing2Ref.RefName = new XmlQualifiedName("thing2"); // <xs:element ref="thing3"/> XmlSchemaElement elementThing3Ref = new XmlSchemaElement(); sequence.Items.Add(elementThing3Ref); elementThing3Ref.RefName = new XmlQualifiedName("thing3"); // <xs:complexType name="myComplexType"> XmlSchemaComplexType myComplexType = new XmlSchemaComplexType(); schema.Items.Add(myComplexType); myComplexType.Name = "myComplexType"; // <xs:group ref="myGroupOfThings"/> XmlSchemaGroupRef myGroupOfThingsRef = new XmlSchemaGroupRef(); myComplexType.Particle = myGroupOfThingsRef; myGroupOfThingsRef.RefName = new XmlQualifiedName("myGroupOfThings"); // <xs:attribute ref="myAttribute"/> XmlSchemaAttribute myAttributeRef = new XmlSchemaAttribute(); myComplexType.Attributes.Add(myAttributeRef); myAttributeRef.RefName = new XmlQualifiedName("myAttribute"); 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="thing1" type="xs:string"/> <xs:element name="thing2" type="xs:string"/> <xs:element name="thing3" type="xs:string"/> <xs:attribute name="myAttribute" type="xs:decimal"/> <xs:group name="myGroupOfThings"> <xs:sequence> <xs:element ref="thing1"/> <xs:element ref="thing2"/> <xs:element ref="thing3"/> </xs:sequence> </xs:group> <xs:complexType name="myComplexType"> <xs:group ref="myGroupOfThings"/> <xs:attribute ref="myAttribute"/> </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. |
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. |
Items | Read-only Overridden: The elements contained within the compositor. Collection of XmlSchemaElement, XmlSchemaGroupRef, XmlSchemaChoice, XmlSchemaSequence, or XmlSchemaAny. |
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. |
MaxOccurs (inherited from System.Xml.Schema.XmlSchemaParticle) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaParticle.MaxOccurs Gets or sets the maximum number of times the particle can occur. |
MaxOccursString (inherited from System.Xml.Schema.XmlSchemaParticle) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaParticle.MaxOccursString Gets or sets the number as a string value. Maximum number of times the particle can occur. |
MinOccurs (inherited from System.Xml.Schema.XmlSchemaParticle) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaParticle.MinOccurs Gets or sets the minimum number of times the particle can occur. |
MinOccursString (inherited from System.Xml.Schema.XmlSchemaParticle) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaParticle.MinOccursString Gets or sets the number as a string value. The minimum number of times the particle can occur. |
Namespaces (inherited from System.Xml.Schema.XmlSchemaObject) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaObject.Namespaces |
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 XmlSchemaSequence(); |
public XmlSchemaAnnotation Annotation {get; set;}
|
public string Id {get; set;}
|
Optional.
public override XmlSchemaObjectCollection Items {get;}
|
public int LineNumber {get; set;}
|
public int LinePosition {get; set;}
|
public decimal MaxOccurs {get; set;}
|
public string MaxOccursString {get; set;}
|
To set no limit on the maximum number, use the string "unbounded".
public decimal MinOccurs {get; set;}
|
public string MinOccursString {get; set;}
|
public XmlSerializerNamespaces Namespaces {get; set;}
|
public string SourceUri {get; set;}
|
public XmlAttribute[] UnhandledAttributes {get; set;}
|
~XmlSchemaSequence(); |
public virtual int GetHashCode(); |
public Type GetType(); |
protected object MemberwiseClone(); |
public virtual string ToString(); |