public class XmlSchema : XmlSchemaObject
|
using System; using System.Xml; using System.Xml.Schema; class XMLSchemaExamples { public static void Main() { XmlSchema schema = new XmlSchema(); // <xs:element name="cat" type="xs: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="xs: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 generated 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" type="xs:string" substitutionGroup="dog"/> <xs:element name="brownDog" type="xs:string" 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. Constructs a new, empty schema. |
InstanceNamespace | Provides the instance namespace. |
Namespace | Provides the namespace for validation. |
AttributeFormDefault | Read-write Gets or sets the form for attributes declared in the target namespace of the schema. |
AttributeGroups | Read-only Gets the XmlSchemaObjectTable for all attribute groups in the schema, which holds the post-compilation value of the AttributeGroups property. |
Attributes | Read-only Gets the XmlSchemaObjectTable, for all attributes in the schema, which holds the post-compilation value of the Attribute property. |
BlockDefault | Read-write Gets or sets the BlockDefault attribute on element and complex type elements in the targetNamespace of the schema. The block attribute prevents a complex type (or element) that has the specified type of derivation from being used in place of the inherited complex type (or element). The type of derivation. |
ElementFormDefault | Read-write Gets or sets the form for elements declared in the target namespace of the schema. |
Elements | Read-only Gets the XmlSchemaObjectTable for all elements in the schema, which holds the post-compilation value of the Elements property. |
FinalDefault | Read-write Gets or sets the default value of the final attribute on element and complex type elements in the target namespace of this schema. The final attribute prevents the specified type of derivation of an element or complex type. The type of derivation. |
Groups | Read-only Gets the XmlSchemaObjectTable for all groups in the schema, which holds the post-compilation value of the Groups property. |
Id | Read-write Gets or sets the string id. |
Includes | Read-only Gets the collection of included and imported schemas. |
IsCompiled | Read-only Gets information that indicates if the schema has been compiled. |
Items | Read-only Gets the Items collection that is used to add new element types at the schema element level. |
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 |
Notations | Read-only Gets the XmlSchemaObjectTable for all notations in the schema. |
SchemaTypes | Read-only Gets the XmlSchemaObjectTable for all schema types in the schema, which holds the post-compilation value of the SchemaTypes property. |
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. |
TargetNamespace | Read-write Gets or sets the property for the schema target namespace. The URI reference of the namespace of this schema. |
UnhandledAttributes | Read-write Gets and sets the qualified attributes which do not belong to the schema target namespace. |
Version | Read-write Gets or sets the version of the schema. |
Compile | Compiles the XML Schema definition language (XSD) Schema Object Model (SOM) into schema information for validation. Used to check the syntactic and semantic structure of the programmatically-built SOM. Semantic validation checking is performed during compilation. |
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. |
Read | Overloaded:Read(Stream stream, ValidationEventHandler validationEventHandler) Reads an XML Schema fefinition language (XSD) schema from the supplied stream. |
Read | Overloaded:Read(TextReader reader, ValidationEventHandler validationEventHandler) Reads an XSD Schema from the supplied text reader. |
Read | Overloaded:Read(XmlReader reader, ValidationEventHandler validationEventHandler) Reads an XML Schema definition language (XSD) schema from the supplied reader. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
Write | Overloaded:Write(Stream stream) Writes the XML Schema to the supplied data stream. |
Write | Overloaded:Write(TextWriter writer) Writes the XML Schema definition language (XSD) schema to the supplied TextWriter. |
Write | Overloaded:Write(XmlWriter writer) Writes the XML Schema Definition language (XSD) schema to the supplied XmlWriter. |
Write | Overloaded:Write(Stream stream, XmlNamespaceManager namespaceManager) Writes the XML Schema definition language (XSD) schema to the supplied stream. |
Write | Overloaded:Write(TextWriter writer, XmlNamespaceManager namespaceManager) Writes the XML Schema definition language (XSD) schema to the supplied TextWriter. |
Write | Overloaded:Write(XmlWriter writer, XmlNamespaceManager namespaceManager) Writes the XML Schema Definition language (XSD) schema to the supplied XmlWriter. |
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 XmlSchema(); |
public const string InstanceNamespace;
|
public const string Namespace;
|
public XmlSchemaForm AttributeFormDefault {get; set;}
|
Enum | Description |
---|---|
Qualified | Attributes from the target namespace must be qualified with the namespace prefix. |
Unqualified | Attributes from the target namespace are not required to be qualified with the namespace prefix. |
This value is the global default for all attributes declared in the targetNamespace. Individual attributes can override this setting for the local scope using the form attribute.
public XmlSchemaObjectTable AttributeGroups {get;}
|
public XmlSchemaObjectTable Attributes {get;}
|
public XmlSchemaDerivationMethod BlockDefault {get; set;}
|
Enum | Description |
---|---|
None | By default, there are no restrictions on replacements of elements in this schema. |
Empty | By default, there are no restrictions on replacements of elements in this schema. |
Substitution | By default, elements in the schema cannot be replaced by a type derived by Substitution. |
Extension | By default, elements in the schema cannot be replaced by a type derived by Extension. |
Restriction | By default, elements in the schema cannot be replaced by a type derived by Restriction. |
All | #all . By default, elements in the schema cannot be replaced by any type regardless of derivation method. |
public XmlSchemaForm ElementFormDefault {get; set;}
|
Enum | Description |
---|---|
Qualified | Elements from the target namespace must be qualified with the namespace prefix. |
Unqualified | Elements from the target namespace are not required to be qualified with the namespace prefix. |
This value is the global default for all elements declared in the target namespace. Individual elements can override this setting for the local scope by using the form attribute.
public XmlSchemaObjectTable Elements {get;}
|
public XmlSchemaDerivationMethod FinalDefault {get; set;}
|
Enum | Description |
---|---|
None | By default, there are no restrictions on type derivations in the schema. |
Empty | By default, there are no restrictions on type derivations in the schema. |
Extension | By default, elements in this schema cannot be derived by Extension. Applies only to element and complex type elements. |
Restriction | By default, elements in this schema cannot be derived by Restriction. |
Union | By default, elements in this schema cannot be derived by Union. Applies only to simple types. |
List | By default, elements in this schema cannot be derived by List. Applies only to simple types. |
All | #all . By default, elements in this schema cannot be derived by any method. |
public XmlSchemaObjectTable Groups {get;}
|
public string Id {get; set;}
|
public XmlSchemaObjectCollection Includes {get;}
|
public bool IsCompiled {get;}
|
public XmlSchemaObjectCollection Items {get;}
|
public int LineNumber {get; set;}
|
public int LinePosition {get; set;}
|
public XmlSerializerNamespaces Namespaces {get; set;}
|
public XmlSchemaObjectTable Notations {get;}
|
public XmlSchemaObjectTable SchemaTypes {get;}
|
public string SourceUri {get; set;}
|
public string TargetNamespace {get; set;}
|
public XmlAttribute[] UnhandledAttributes {get; set;}
|
public string Version {get; set;}
|
public void Compile( |
validationEventHandler
~XmlSchema(); |
public virtual int GetHashCode(); |
public Type GetType(); |
protected object MemberwiseClone(); |
public static XmlSchema Read( |
stream
validationEventHandler
public static XmlSchema Read(TextRead( |
reader
validationEventHandler
public static XmlSchema Read(XmlRead( |
reader
validationEventHandler
public virtual string ToString(); |
public void Write( |
stream
public void Write(TextWrite( |
writer
public void Write(XmlWrite( |
writer
public void Write( |
stream
namespaceManager
public void Write(TextWrite( |
writer
namespaceManager
public void Write(XmlWrite( |
writer
namespaceManager