public class XmlSchemaElement : XmlSchemaParticle
|
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"); 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="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>
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. |
Block | Read-write Gets or sets a Block derivation. |
BlockResolved | Read-only Gets the post-compilation value of the Block property which holds the post-compilation value of the Block property. |
Constraints | Read-only Gets the collection of constraints on the element. |
DefaultValue | Read-write Gets or sets the default value of the element if its content is a simple type or content of the element is textOnly. |
ElementType | Read-only 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 | Read-write Gets or sets the Final property to indicate that no further derivations are allowed. |
FinalResolved | Read-only Gets the post-compilation value of the Final property which holds the post-compilation value of the Final property. |
FixedValue | Read-write Gets or sets the fixed value. |
Form | Read-write Gets or sets the form for the element. |
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. |
IsAbstract | Read-write Gets or sets information to indicate if the element can be used in an instance document. |
IsNillable | Read-write 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 (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. |
Name | Read-write Gets or sets the name of the element. |
Namespaces (inherited from System.Xml.Schema.XmlSchemaObject) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaObject.Namespaces |
QualifiedName | Read-only Gets the actual qualified name for the given element. This is the name that a ref attribute refers to. The qualified name consists of the NCName of the element. For example, element name = "NCName", and the prefix used to describe the targetNamespace of the schema. This property holds the post-compilation value of the QualifiedName property. |
RefName | Read-write Gets or sets the reference name of an element declared in this schema (or another schema indicated by the specified namespace). |
SchemaType | Read-write Gets or sets the type of the element. This can either be a complex type or a simple type. |
SchemaTypeName | Read-write Gets or sets the name of a built-in data type defined in this schema or another schema indicated by the specified namespace. |
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. |
SubstitutionGroup | Read-write Gets or sets the name of an element that is being substituted by this element. |
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 XmlSchemaElement(); |
public XmlSchemaAnnotation Annotation {get; set;}
|
public XmlSchemaDerivationMethod Block {get; set;}
|
Enum | Description |
---|---|
None | Use the derivation restriction defined by the BlockDefault property of the schema, if it exists. |
Empty | There are no restrictions on replacements of this element. |
Substitution | This element cannot be replaced by a type derived by Substitution. |
Extension | This element cannot be replaced by a type derived by Extension. |
Restriction | This element cannot be replaced by a type derived by Restriction. |
All | #all . This element cannot be replaced by any type regardless of derivation method. |
This property does not prevent derivation but prevents derivation from replacing the type in an instance. List and union values are not supported for the block property.
public XmlSchemaDerivationMethod BlockResolved {get;}
|
Enum | Description |
---|---|
Empty | There are no restrictions on replacements of this element. |
Substitution | This element cannot be replaced by a type derived by Substitution. |
Extension | This element cannot be replaced by a type derived by Extension. |
Restriction | This element cannot be replaced by a type derived by Restriction. |
All | #all . This element cannot be replaced by any type regardless of derivation method. |
public XmlSchemaObjectCollection Constraints {get;}
|
public string DefaultValue {get; set;}
|
public object ElementType {get;}
|
This property is a post-schema-validation infoset property.
public XmlSchemaDerivationMethod Final {get; set;}
|
Enum | Description |
---|---|
None | Use the derivation restriction defined by the FinalDefault property of the schema, if it exists. |
Empty | There are no restrictions on derivations of this element. |
Extension | This element cannot be derived by Extension. |
Restriction | This element cannot be derived by Restriction. |
All | #all . This element cannot be derived by any derivation method. |
public XmlSchemaDerivationMethod FinalResolved {get;}
|
Enum | Description |
---|---|
Empty | There are no restrictions on derivations of this element. |
Extension | This element cannot be derived by Extension. |
Restriction | This element cannot be derived by Restriction. |
All | #all . This element cannot be derived by any derivation method. |
public string FixedValue {get; set;}
|
public XmlSchemaForm Form {get; set;}
|
Enum | Description |
---|---|
Qualified | Element must be qualified with the namespace prefix. |
Unqualified | Element is not required to be qualified with the namespace prefix. |
The value cannot be set if the containing element is the schema element.
public string Id {get; set;}
|
Optional.
public bool IsAbstract {get; set;}
|
public bool IsNillable {get; set;}
|
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 string Name {get; set;}
|
public XmlSerializerNamespaces Namespaces {get; set;}
|
public XmlQualifiedName QualifiedName {get;}
|
public XmlQualifiedName RefName {get; set;}
|
The value cannot be set if the containing element is the schema element.
public XmlSchemaType SchemaType {get; set;}
|
public XmlQualifiedName SchemaTypeName {get; set;}
|
public string SourceUri {get; set;}
|
public XmlQualifiedName SubstitutionGroup {get; set;}
|
The value cannot be set if the containing element is the schema element.
public XmlAttribute[] UnhandledAttributes {get; set;}
|
~XmlSchemaElement(); |
public virtual int GetHashCode(); |
public Type GetType(); |
protected object MemberwiseClone(); |
public virtual string ToString(); |