XmlSchemaSimpleTypeUnion Class
Represents the union element for simple types from XML Schema as specified by the World Wide Web Consortium (W3C). A union datatype can be used to specify the content of a simpleType. The value of the simpleType element must be any one of a set of alternative datatypes specified in the union. Union types are always derived types and must comprise at least two alternative datatypes.
Assembly: System.Xml (in System.Xml.dll)
System.Xml.Schema::XmlSchemaObject
System.Xml.Schema::XmlSchemaAnnotated
System.Xml.Schema::XmlSchemaSimpleTypeContent
System.Xml.Schema::XmlSchemaSimpleTypeUnion
| Name | Description | |
|---|---|---|
![]() | XmlSchemaSimpleTypeUnion() | Initializes a new instance of the XmlSchemaSimpleTypeUnion class. |
| Name | Description | |
|---|---|---|
![]() | Annotation | Gets or sets the annotation property.(Inherited from XmlSchemaAnnotated.) |
![]() | BaseMemberTypes | Gets an array of XmlSchemaSimpleType objects representing the type of the simpleType element based on the BaseTypes and MemberTypes values of the simple type. |
![]() | BaseTypes | Gets the collection of base types. |
![]() | Id | Gets or sets the string id.(Inherited from XmlSchemaAnnotated.) |
![]() | 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.) |
![]() | MemberTypes | 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 | 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.) |
![]() | SourceUri | Gets or sets the source location for the file that loaded the schema.(Inherited from XmlSchemaObject.) |
![]() | 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 the default hash function. (Inherited from Object.) |
![]() | GetType() | |
![]() | MemberwiseClone() | |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
A union type enables an element or attribute value to be one or more instances of one type drawn from the union of multiple atomic and list types.
The following example shows the use of XmlSchemaSimpleTypeUnion class.
#using <System.Xml.dll> using namespace System; using namespace System::Xml; using namespace System::Xml::Schema; ref class XMLSchemaExamples { private: static void ValidationCallbackOne(Object^ sender, ValidationEventArgs^ args) { Console::WriteLine(args->Message); } public: static void Main() { XmlSchema^ schema = gcnew XmlSchema(); //<xs:simpleType name="StringOrIntType"> XmlSchemaSimpleType^ StringOrIntType = gcnew XmlSchemaSimpleType(); StringOrIntType->Name = "StringOrIntType"; schema->Items->Add(StringOrIntType); // <xs:union> XmlSchemaSimpleTypeUnion^ union1 = gcnew XmlSchemaSimpleTypeUnion(); StringOrIntType->Content = union1; // <xs:simpleType> XmlSchemaSimpleType^ simpleType1 = gcnew XmlSchemaSimpleType(); union1->BaseTypes->Add(simpleType1); // <xs:restriction base="xs:string"/> XmlSchemaSimpleTypeRestriction^ restriction1 = gcnew XmlSchemaSimpleTypeRestriction(); restriction1->BaseTypeName = gcnew XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); simpleType1->Content = restriction1; // <xs:simpleType> XmlSchemaSimpleType^ simpleType2 = gcnew XmlSchemaSimpleType(); union1->BaseTypes->Add(simpleType2); // <xs:restriction base="xs:int"/> XmlSchemaSimpleTypeRestriction^ restriction2 = gcnew XmlSchemaSimpleTypeRestriction(); restriction2->BaseTypeName = gcnew XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema"); simpleType2->Content = restriction2; // <xs:element name="size" type="StringOrIntType"/> XmlSchemaElement^ elementSize = gcnew XmlSchemaElement(); elementSize->Name = "size"; elementSize->SchemaTypeName = gcnew XmlQualifiedName("StringOrIntType"); schema->Items->Add(elementSize); XmlSchemaSet^ schemaSet = gcnew XmlSchemaSet(); schemaSet->ValidationEventHandler += gcnew ValidationEventHandler(ValidationCallbackOne); schemaSet->Add(schema); schemaSet->Compile(); XmlSchema^ compiledSchema = nullptr; for each (XmlSchema^ schema1 in schemaSet->Schemas()) { compiledSchema = schema1; } XmlNamespaceManager^ nsmgr = gcnew XmlNamespaceManager(gcnew NameTable()); nsmgr->AddNamespace("xs", "http://www.w3.org/2001/XMLSchema"); compiledSchema->Write(Console::Out, nsmgr); } }; int main() { XMLSchemaExamples::Main(); return 0; }
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>
Available since 1.1
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


