Export (0) Print
Expand All

XmlSchemaElement Class

Represents the element element from XML Schema as specified by the World Wide Web Consortium (W3C). This class is the base class for all particle types and is used to describe an element in an XML document.

Namespace:  System.Xml.Schema
Assembly:  System.Xml (in System.Xml.dll)

public class XmlSchemaElement : XmlSchemaParticle

The XmlSchemaElement type exposes the following members.

  NameDescription
Public methodSupported by the XNA FrameworkXmlSchemaElementInitializes a new instance of the XmlSchemaElement class.
Top

  NameDescription
Public propertySupported by the XNA FrameworkAnnotationGets or sets the annotation property. (Inherited from XmlSchemaAnnotated.)
Public propertySupported by the XNA FrameworkBlockGets or sets a Block derivation.
Public propertySupported by the XNA FrameworkBlockResolvedGets the post-compilation value of the Block property.
Public propertySupported by the XNA FrameworkConstraintsGets the collection of constraints on the element.
Public propertySupported by the XNA FrameworkDefaultValueGets or sets the default value of the element if its content is a simple type or content of the element is textOnly.
Public propertySupported by the XNA FrameworkElementSchemaTypeGets an XmlSchemaType object representing the type of the element based on the SchemaType or SchemaTypeName values of the element.
Public propertySupported by the XNA FrameworkElementType 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.
Public propertySupported by the XNA FrameworkFinalGets or sets the Final property to indicate that no further derivations are allowed.
Public propertySupported by the XNA FrameworkFinalResolvedGets the post-compilation value of the Final property.
Public propertySupported by the XNA FrameworkFixedValueGets or sets the fixed value.
Public propertySupported by the XNA FrameworkFormGets or sets the form for the element.
Public propertySupported by the XNA FrameworkIdGets or sets the string id. (Inherited from XmlSchemaAnnotated.)
Public propertySupported by the XNA FrameworkIsAbstractGets or sets information to indicate if the element can be used in an instance document.
Public propertySupported by the XNA FrameworkIsNillableGets 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.
Public propertySupported by the XNA FrameworkLineNumberGets or sets the line number in the file to which the schema element refers. (Inherited from XmlSchemaObject.)
Public propertySupported by the XNA FrameworkLinePositionGets or sets the line position in the file to which the schema element refers. (Inherited from XmlSchemaObject.)
Public propertySupported by the XNA FrameworkMaxOccursGets or sets the maximum number of times the particle can occur. (Inherited from XmlSchemaParticle.)
Public propertySupported by the XNA FrameworkMaxOccursStringGets or sets the number as a string value. Maximum number of times the particle can occur. (Inherited from XmlSchemaParticle.)
Public propertySupported by the XNA FrameworkMinOccursGets or sets the minimum number of times the particle can occur. (Inherited from XmlSchemaParticle.)
Public propertySupported by the XNA FrameworkMinOccursStringGets or sets the number as a string value. The minimum number of times the particle can occur. (Inherited from XmlSchemaParticle.)
Public propertySupported by the XNA FrameworkNameGets or sets the name of the element.
Public propertySupported by the XNA FrameworkNamespacesGets or sets the XmlSerializerNamespaces to use with this schema object. (Inherited from XmlSchemaObject.)
Public propertySupported by the XNA FrameworkParentGets or sets the parent of this XmlSchemaObject. (Inherited from XmlSchemaObject.)
Public propertySupported by the XNA FrameworkQualifiedNameGets the actual qualified name for the given element.
Public propertySupported by the XNA FrameworkRefNameGets or sets the reference name of an element declared in this schema (or another schema indicated by the specified namespace).
Public propertySupported by the XNA FrameworkSchemaTypeGets or sets the type of the element. This can either be a complex type or a simple type.
Public propertySupported by the XNA FrameworkSchemaTypeNameGets or sets the name of a built-in data type defined in this schema or another schema indicated by the specified namespace.
Public propertySupported by the XNA FrameworkSourceUriGets or sets the source location for the file that loaded the schema. (Inherited from XmlSchemaObject.)
Public propertySupported by the XNA FrameworkSubstitutionGroupGets or sets the name of an element that is being substituted by this element.
Public propertySupported by the XNA FrameworkUnhandledAttributesGets or sets the qualified attributes that do not belong to the current schema's target namespace. (Inherited from XmlSchemaAnnotated.)
Top

  NameDescription
Public methodSupported by the XNA FrameworkEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by the XNA FrameworkToStringReturns a string that represents the current object. (Inherited from Object.)
Top

Security noteSecurity Note
  • Do not use schemas from unknown or untrusted sources or locations. Doing so will compromise the security of your code.

  • XML schemas (including inline schemas) are inherently vulnerable to denial of service attacks; do not accept them in untrusted scenarios.

  • Schema validation error messages and exceptions may expose sensitive information about the content model or URI paths to the schema file. Be careful not to expose this information to untrusted callers.

The following example creates the element element.

using System;
using System.Xml;
using System.Xml.Schema;

class XMLSchemaExamples
{
    public static void Main()
    {

        XmlSchema schema = new XmlSchema();

        // <xs:element name="cat" type="string"/>
        XmlSchemaElement elementCat = 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"/>
        XmlSchemaElement elementDog = 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" />
        XmlSchemaElement elementRedDog = new XmlSchemaElement();
        schema.Items.Add(elementRedDog);
        elementRedDog.Name = "redDog";
        elementRedDog.SubstitutionGroup = new XmlQualifiedName("dog");


        // <xs:element name="brownDog" substitutionGroup ="dog" />
        XmlSchemaElement elementBrownDog = new XmlSchemaElement();
        schema.Items.Add(elementBrownDog);
        elementBrownDog.Name = "brownDog";
        elementBrownDog.SubstitutionGroup = new XmlQualifiedName("dog");


        // <xs:element name="pets">
        XmlSchemaElement elementPets = new XmlSchemaElement();
        schema.Items.Add(elementPets);
        elementPets.Name = "pets";

        // <xs:complexType>
        XmlSchemaComplexType complexType = new XmlSchemaComplexType();
        elementPets.SchemaType = complexType;

        // <xs:choice minOccurs="0" maxOccurs="unbounded">
        XmlSchemaChoice choice = new XmlSchemaChoice();
        complexType.Particle = choice;
        choice.MinOccurs = 0;
        choice.MaxOccursString = "unbounded";

        // <xs:element ref="cat"/>
        XmlSchemaElement catRef = new XmlSchemaElement();
        choice.Items.Add(catRef);
        catRef.RefName = new XmlQualifiedName("cat");

        // <xs:element ref="dog"/>
        XmlSchemaElement dogRef = new XmlSchemaElement();
        choice.Items.Add(dogRef);
        dogRef.RefName = new XmlQualifiedName("dog");

        XmlSchemaSet schemaSet = new XmlSchemaSet();
        schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne);
        schemaSet.Add(schema);
        schemaSet.Compile();

        XmlSchema compiledSchema = null;

        foreach (XmlSchema schema1 in schemaSet.Schemas())
        {
            compiledSchema = schema1;
        }

        XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
        nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
        compiledSchema.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="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>

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft