This documentation is archived and is not being maintained.

XmlSchemaSimpleTypeUnion Class

Class for the union of simpleType elements. Defines a simpleType element as a list of values of a specified data type. Represents the World Wide Web Consortium (W3C) union element.

For a list of all members of this type, see XmlSchemaSimpleTypeUnion Members.


[Visual Basic]
Public Class XmlSchemaSimpleTypeUnion
   Inherits XmlSchemaSimpleTypeContent
public class XmlSchemaSimpleTypeUnion : XmlSchemaSimpleTypeContent
public __gc class XmlSchemaSimpleTypeUnion : public
public class XmlSchemaSimpleTypeUnion extends

Thread Safety

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


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.


[Visual Basic, C#, C++] The following example shows the use of XmlSchemaSimpleTypeUnion class.

[Visual Basic] 
Imports System
Imports System.Xml
Imports System.Xml.Schema

class XMLSchemaExamples
    Public Shared Sub Main()
        Dim schema As New XmlSchema()
        ' <xs:simpleType name="StringOrIntType">
        Dim StringOrIntType As New XmlSchemaSimpleType()
        ' <xs:union>
        Dim union As New XmlSchemaSimpleTypeUnion
        StringOrIntType.Content = union
        ' <xs:simpleType>
        Dim simpleType1 As New XmlSchemaSimpleType
        ' <xs:restriction base="xs:string"/>
        Dim restriction1 As New XmlSchemaSimpleTypeRestriction()
        restriction1.BaseTypeName = new XmlQualifiedName("string", "")
        simpleType1.Content = restriction1
        ' <xs:simpleType>
        Dim simpleType2 As New XmlSchemaSimpleType()
        ' <xs:restriction base="xs:int"/>
        Dim restriction2 As New XmlSchemaSimpleTypeRestriction()
        restriction2.BaseTypeName = new XmlQualifiedName("int", "")
        simpleType2.Content = restriction2

        ' <xs:element name="size" type="StringOrIntType"/>
        Dim elementSize As New XmlSchemaElement()
        elementSize.Name = "size"
        elementSize.SchemaTypeName = new XmlQualifiedName("StringOrIntType")
    schema.Compile(AddressOf ValidationCallbackOne)
    Dim nsmgr As New XmlNamespaceManager(New NameTable())
    nsmgr.AddNamespace("xs", "")
    schema.Write(Console.Out, nsmgr)
  End Sub

    Public Shared Sub ValidationCallbackOne(sender As object, args as ValidationEventArgs)
    End Sub
End class

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";
        // <xs:union>
        XmlSchemaSimpleTypeUnion union = new XmlSchemaSimpleTypeUnion();
        StringOrIntType.Content = union;
        // <xs:simpleType>
        XmlSchemaSimpleType simpleType1 = new XmlSchemaSimpleType();
        // <xs:restriction base="xs:string"/>
        XmlSchemaSimpleTypeRestriction restriction1 = new XmlSchemaSimpleTypeRestriction();
        restriction1.BaseTypeName = new XmlQualifiedName("string", "");
        simpleType1.Content = restriction1;
        // <xs:simpleType>
        XmlSchemaSimpleType simpleType2 = new XmlSchemaSimpleType();
        // <xs:restriction base="xs:int"/>
        XmlSchemaSimpleTypeRestriction restriction2 = new XmlSchemaSimpleTypeRestriction();
        restriction2.BaseTypeName = new XmlQualifiedName("int", "");
        simpleType2.Content = restriction2;

        // <xs:element name="size" type="StringOrIntType"/>
        XmlSchemaElement elementSize = new XmlSchemaElement();
        elementSize.Name = "size";
        elementSize.SchemaTypeName = new XmlQualifiedName("StringOrIntType");
        schema.Compile(new ValidationEventHandler(ValidationCallbackOne));
     XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
        nsmgr.AddNamespace("xs", "");
        schema.Write(Console.Out, nsmgr);

    public static void ValidationCallbackOne(object sender, ValidationEventArgs args) {

#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;  
using namespace System::Xml::Schema;

__gc class XMLSchemaExamples 
   static void ValidationCallbackOne(Object* sender, ValidationEventArgs * args) 
      Console::WriteLine(args -> Message);

int main() 
   XmlSchema* schema = new XmlSchema();

   //<xs:simpleType name=S"StringOrIntType">
   XmlSchemaSimpleType* StringOrIntType = new XmlSchemaSimpleType();
   StringOrIntType -> Name = S"StringOrIntType";
   schema -> Items->Add(StringOrIntType);

   // <xs:union>
   XmlSchemaSimpleTypeUnion* MyUnion = new XmlSchemaSimpleTypeUnion();
   StringOrIntType -> Content = MyUnion;

   // <xs:simpleType>
   XmlSchemaSimpleType* simpleType1 = new XmlSchemaSimpleType();
   MyUnion -> BaseTypes->Add(simpleType1);

   // <xs:restriction base=S"xs:string"/>
   XmlSchemaSimpleTypeRestriction* restriction1 = new XmlSchemaSimpleTypeRestriction();
   restriction1 -> BaseTypeName = new XmlQualifiedName(S"string", S"");
   simpleType1 -> Content = restriction1;

   // <xs:simpleType>
   XmlSchemaSimpleType* simpleType2 = new XmlSchemaSimpleType();
   MyUnion -> BaseTypes->Add(simpleType2);

   // <xs:restriction base=S"xs:int"/>
   XmlSchemaSimpleTypeRestriction* restriction2 = new XmlSchemaSimpleTypeRestriction();
   restriction2 -> BaseTypeName = new XmlQualifiedName(S"int", S"");
   simpleType2 -> Content = restriction2;

   // <xs:element name=S"size" type=S"StringOrIntType"/>
   XmlSchemaElement* elementSize = new XmlSchemaElement();
   elementSize -> Name = S"size";
   elementSize -> SchemaTypeName = new XmlQualifiedName(S"StringOrIntType");
   schema -> Items->Add(elementSize);

   schema -> Compile(new ValidationEventHandler(schema, XMLSchemaExamples::ValidationCallbackOne));
   XmlNamespaceManager* nsmgr = new XmlNamespaceManager(new NameTable());
   nsmgr -> AddNamespace(S"xs", S"");
   schema -> Write(Console::Out, nsmgr);

[Visual Basic, C#, C++] The following XML file is generated for this code example.

<?xml version="1.0" encoding="IBM437"?>
<xs:schema xmlns:xs="">

    <xs:simpleType name="StringOrIntType">
                <xs:restriction base="xs:string"/>
                <xs:restriction base="xs:int"/>
    <xs:element name="size" type="StringOrIntType"/>

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Namespace: System.Xml.Schema

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

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

See Also

XmlSchemaSimpleTypeUnion Members | System.Xml.Schema Namespace