XmlSchemaElement Class
Represents the element element from XML Schema as specified by the . This class is the base class for all particle types and is used to describe an element in an XML document.
System.Xml.Schema.XmlSchemaObject
System.Xml.Schema.XmlSchemaAnnotated
System.Xml.Schema.XmlSchemaParticle
System.Xml.Schema.XmlSchemaElement
Assembly: System.Xml (in System.Xml.dll)
The XmlSchemaElement type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() | Annotation | Gets or sets the annotation property. (Inherited from XmlSchemaAnnotated.) |
![]() ![]() | Block | Gets or sets a Block derivation. |
![]() ![]() | BlockResolved | Gets the post-compilation value of the Block property. |
![]() ![]() | Constraints | Gets the collection of constraints on the element. |
![]() ![]() | DefaultValue | Gets or sets the default value of the element if its content is a simple type or content of the element is textOnly. |
![]() ![]() | ElementSchemaType | Gets an XmlSchemaType object representing the type of the element based on the SchemaType or SchemaTypeName values of the element. |
![]() ![]() | ElementType | Obsolete. Gets a common language runtime (CLR) object based on the XmlSchemaElement or XmlSchemaElement of the element, which holds the post-compilation value of the ElementType property. |
![]() ![]() | Final | Gets or sets the Final property to indicate that no further derivations are allowed. |
![]() ![]() | FinalResolved | Gets the post-compilation value of the Final property. |
![]() ![]() | FixedValue | Gets or sets the fixed value. |
![]() ![]() | Form | Gets or sets the form for the element. |
![]() ![]() | Id | Gets or sets the string id. (Inherited from XmlSchemaAnnotated.) |
![]() ![]() | IsAbstract | Gets or sets information to indicate if the element can be used in an instance document. |
![]() ![]() | IsNillable | Gets or sets information that indicates if xsi:nil can occur in the instance data. Indicates if an explicit nil value can be assigned to the element. |
![]() ![]() | 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.) |
![]() ![]() | MaxOccurs | Gets or sets the maximum number of times the particle can occur. (Inherited from XmlSchemaParticle.) |
![]() ![]() | MaxOccursString | Gets or sets the number as a string value. Maximum number of times the particle can occur. (Inherited from XmlSchemaParticle.) |
![]() ![]() | MinOccurs | Gets or sets the minimum number of times the particle can occur. (Inherited from XmlSchemaParticle.) |
![]() ![]() | MinOccursString | Gets or sets the number as a string value. The minimum number of times the particle can occur. (Inherited from XmlSchemaParticle.) |
![]() ![]() | Name | Gets or sets the name of the element. |
![]() ![]() | 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.) |
![]() ![]() | QualifiedName | Gets the actual qualified name for the given element. |
![]() ![]() | RefName | Gets or sets the reference name of an element declared in this schema (or another schema indicated by the specified namespace). |
![]() ![]() | SchemaType | Gets or sets the type of the element. This can either be a complex type or a simple type. |
![]() ![]() | SchemaTypeName | Gets or sets the name of a built-in data type defined in this schema or another schema indicated by the specified namespace. |
![]() ![]() | SourceUri | Gets or sets the source location for the file that loaded the schema. (Inherited from XmlSchemaObject.) |
![]() ![]() | SubstitutionGroup | Gets or sets the name of an element that is being substituted by this element. |
![]() ![]() | 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 the element element.
Imports System Imports System.Xml Imports System.Xml.Schema Class XMLSchemaExamples Public Shared Sub Main() Dim schema As New XmlSchema() ' <xs:element name="cat" type="string"/> Dim elementCat As New XmlSchemaElement() schema.Items.Add(elementCat) elementCat.Name = "cat" elementCat.SchemaTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema") ' <xs:element name="dog" type="string"/> Dim elementDog As New XmlSchemaElement() schema.Items.Add(elementDog) elementDog.Name = "dog" elementDog.SchemaTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema") ' <xs:element name="redDog" substitutionGroup="dog" /> Dim elementRedDog As New XmlSchemaElement() schema.Items.Add(elementRedDog) elementRedDog.Name = "redDog" elementRedDog.SubstitutionGroup = New XmlQualifiedName("dog") ' <xs:element name="brownDog" substitutionGroup ="dog" /> Dim elementBrownDog As New XmlSchemaElement() schema.Items.Add(elementBrownDog) elementBrownDog.Name = "brownDog" elementBrownDog.SubstitutionGroup = New XmlQualifiedName("dog") ' <xs:element name="pets"> Dim elementPets As New XmlSchemaElement() schema.Items.Add(elementPets) elementPets.Name = "pets" ' <xs:complexType> Dim complexType As New XmlSchemaComplexType() elementPets.SchemaType = complexType ' <xs:choice minOccurs="0" maxOccurs="unbounded"> Dim choice As New XmlSchemaChoice() complexType.Particle = choice choice.MinOccurs = 0 choice.MaxOccursString = "unbounded" ' <xs:element ref="cat"/> Dim catRef As New XmlSchemaElement() choice.Items.Add(catRef) catRef.RefName = New XmlQualifiedName("cat") ' <xs:element ref="dog"/> Dim dogRef As New XmlSchemaElement() choice.Items.Add(dogRef) dogRef.RefName = New XmlQualifiedName("dog") 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 Public Shared Sub ValidationCallbackOne(ByVal sender As Object, ByVal args As ValidationEventArgs) Console.WriteLine(args.Message) End Sub End Class
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="cat" type="xs:string"/> <xs:element name="dog" type="xs:string"/> <xs:element name="redDog" substitutionGroup="dog" /> <xs:element name="brownDog" substitutionGroup ="dog" /> <xs:element name="pets"> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element ref="cat"/> <xs:element ref="dog"/> </xs:choice> </xs:complexType> </xs:element> </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.



