Export (0) Print
Expand All

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.

System.Object
   System.Xml.Schema.XmlSchemaObject
      System.Xml.Schema.XmlSchemaAnnotated
         System.Xml.Schema.XmlSchemaSimpleTypeContent
            System.Xml.Schema.XmlSchemaSimpleTypeUnion

[Visual Basic]
Public Class XmlSchemaSimpleTypeUnion
   Inherits XmlSchemaSimpleTypeContent
[C#]
public class XmlSchemaSimpleTypeUnion : XmlSchemaSimpleTypeContent
[C++]
public __gc class XmlSchemaSimpleTypeUnion : public
   XmlSchemaSimpleTypeContent
[JScript]
public class XmlSchemaSimpleTypeUnion extends
   XmlSchemaSimpleTypeContent

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.

Remarks

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.

Example

[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()
        StringOrIntType.Name="StringOrIntType"
        schema.Items.Add(StringOrIntType)
        
        ' <xs:union>
        Dim union As New XmlSchemaSimpleTypeUnion
        StringOrIntType.Content = union
        
        ' <xs:simpleType>
        Dim simpleType1 As New XmlSchemaSimpleType
        union.BaseTypes.Add(simpleType1)
        
        ' <xs:restriction base="xs:string"/>
        Dim restriction1 As New XmlSchemaSimpleTypeRestriction()
        restriction1.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
        simpleType1.Content = restriction1
        
        ' <xs:simpleType>
        Dim simpleType2 As New XmlSchemaSimpleType()
        union.BaseTypes.Add(simpleType2)
        
        ' <xs:restriction base="xs:int"/>
        Dim restriction2 As New XmlSchemaSimpleTypeRestriction()
        restriction2.BaseTypeName = new XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema")
        simpleType2.Content = restriction2
        

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

    Public Shared Sub ValidationCallbackOne(sender As object, args as ValidationEventArgs)
        Console.WriteLine(args.Message)
    End Sub
End class

[C#] 
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);
    }
}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;  
using namespace System::Xml::Schema;

__gc class XMLSchemaExamples 
{
public:
   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"http://www.w3.org/2001/XMLSchema");
   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"http://www.w3.org/2001/XMLSchema");
   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"http://www.w3.org/2001/XMLSchema");
   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="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>

[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.

Requirements

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

Show:
© 2014 Microsoft