public class XmlSchemaSimpleTypeUnion : XmlSchemaSimpleTypeContent
|
using System; using System.Xml; using System.Xml.Schema; class XMLSchemaExamples { public static void Main() { XmlSchema schema = new XmlSchema(); //<xs:simpleType name="StringOrIntType"> XmlSchemaSimpleType StringOrIntType = new XmlSchemaSimpleType(); StringOrIntType.Name = "StringOrIntType"; schema.Items.Add(StringOrIntType); // <xs:union> XmlSchemaSimpleTypeUnion union = new XmlSchemaSimpleTypeUnion(); StringOrIntType.Content = union; // <xs:simpleType> XmlSchemaSimpleType simpleType1 = new XmlSchemaSimpleType(); union.BaseTypes.Add(simpleType1); // <xs:restriction base="xs:string"/> XmlSchemaSimpleTypeRestriction restriction1 = new XmlSchemaSimpleTypeRestriction(); restriction1.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); simpleType1.Content = restriction1; // <xs:simpleType> XmlSchemaSimpleType simpleType2 = new XmlSchemaSimpleType(); union.BaseTypes.Add(simpleType2); // <xs:restriction base="xs:int"/> XmlSchemaSimpleTypeRestriction restriction2 = new XmlSchemaSimpleTypeRestriction(); restriction2.BaseTypeName = new XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema"); simpleType2.Content = restriction2; // <xs:element name="size" type="StringOrIntType"/> XmlSchemaElement elementSize = new XmlSchemaElement(); elementSize.Name = "size"; elementSize.SchemaTypeName = new XmlQualifiedName("StringOrIntType"); schema.Items.Add(elementSize); 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 this code example.
<?xml version="1.0" encoding="IBM437"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:simpleType name="StringOrIntType"> <xs:union> <xs:simpleType> <xs:restriction base="xs:string"/> </xs:simpleType> <xs:simpleType> <xs:restriction base="xs:int"/> </xs:simpleType> </xs:union> </xs:simpleType> <xs:element name="size" type="StringOrIntType"/> </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. |
BaseTypes | Read-only Gets the collection of base types. |
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. |
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. |
MemberTypes | Read-write Gets or sets the array of qualified member names of built-in data types or simpleType elements defined in this schema (or another schema indicated by the specified namespace). |
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 XmlSchemaSimpleTypeUnion(); |
public XmlSchemaAnnotation Annotation {get; set;}
|
public XmlSchemaObjectCollection BaseTypes {get;}
|
public string Id {get; set;}
|
Optional.
public int LineNumber {get; set;}
|
public int LinePosition {get; set;}
|
public XmlQualifiedName[] MemberTypes {get; set;}
|
public XmlSerializerNamespaces Namespaces {get; set;}
|
public string SourceUri {get; set;}
|
public XmlAttribute[] UnhandledAttributes {get; set;}
|
~XmlSchemaSimpleTypeUnion(); |
public virtual int GetHashCode(); |
public Type GetType(); |
protected object MemberwiseClone(); |
public virtual string ToString(); |