Share via


XmlSchemaSimpleTypeUnion 클래스

정의

W3C(World Wide Web 컨소시엄)에서 지정한 대로 XML 스키마의 단순 형식에 대한 union 요소를 나타냅니다. union 데이터 형식을 사용하여 simpleType의 내용을 지정할 수 있습니다. simpleType 요소의 값은 공용 구조체에 지정된 다른 데이터 형식의 집합 중 하나여야 합니다. 공용 구조체 형식은 항상 파생 형식이며 다른 데이터 형식을 두 개 이상 구성해야 합니다.

public ref class XmlSchemaSimpleTypeUnion : System::Xml::Schema::XmlSchemaSimpleTypeContent
public class XmlSchemaSimpleTypeUnion : System.Xml.Schema.XmlSchemaSimpleTypeContent
type XmlSchemaSimpleTypeUnion = class
    inherit XmlSchemaSimpleTypeContent
Public Class XmlSchemaSimpleTypeUnion
Inherits XmlSchemaSimpleTypeContent
상속

예제

다음 예제에서는 클래스의 XmlSchemaSimpleTypeUnion 사용을 보여 있습니다.

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

        XmlSchemaSet schemaSet = new XmlSchemaSet();
        schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne);
        schemaSet.Add(schema);
        schemaSet.Compile();

        XmlSchema compiledSchema = null;

        foreach (XmlSchema schema1 in schemaSet.Schemas())
        {
            compiledSchema = schema1;
        }

        XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
        nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
        compiledSchema.Write(Console.Out, nsmgr);
    }

    public static void ValidationCallbackOne(object sender, ValidationEventArgs args)
    {
        Console.WriteLine(args.Message);
    }
}
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)

        Dim schemaSet As New XmlSchemaSet()
        AddHandler schemaSet.ValidationEventHandler, AddressOf ValidationCallbackOne

        schemaSet.Add(schema)
        schemaSet.Compile()

        Dim compiledSchema As XmlSchema = Nothing

        For Each schema1 As XmlSchema In schemaSet.Schemas()
            compiledSchema = schema1
        Next

        Dim nsmgr As New XmlNamespaceManager(New NameTable())
        nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema")
        compiledSchema.Write(Console.Out, nsmgr)
    End Sub

    Public Shared Sub ValidationCallbackOne(ByVal sender As Object, ByVal args As ValidationEventArgs)
        Console.WriteLine(args.Message)
    End Sub
End Class

이 코드 예제에 대해 다음 XML 파일이 생성됩니다.

<?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>

설명

union 형식을 사용하면 요소 또는 특성 값이 여러 원자성 및 목록 형식의 공용 구조체에서 가져온 한 형식의 하나 이상의 인스턴스가 될 수 있습니다.

생성자

XmlSchemaSimpleTypeUnion()

XmlSchemaSimpleTypeUnion 클래스의 새 인스턴스를 초기화합니다.

속성

Annotation

annotation 속성을 가져오거나 설정합니다.

(다음에서 상속됨 XmlSchemaAnnotated)
BaseMemberTypes

단순 형식의 XmlSchemaSimpleTypeBaseTypes 값에 따라 simpleType 요소의 형식을 나타내는 MemberTypes 개체의 배열을 가져옵니다.

BaseTypes

기본 형식의 컬렉션을 가져옵니다.

Id

문자열 ID를 가져오거나 설정합니다.

(다음에서 상속됨 XmlSchemaAnnotated)
LineNumber

schema 요소가 참조하는 파일에서 줄 번호를 가져오거나 설정합니다.

(다음에서 상속됨 XmlSchemaObject)
LinePosition

schema 요소가 참조하는 파일에서 줄 위치를 가져오거나 설정합니다.

(다음에서 상속됨 XmlSchemaObject)
MemberTypes

이 스키마 또는 지정된 네임스페이스가 나타내는 다른 스키마에 정의된 기본 제공 데이터 형식 또는 simpleType 요소의 한정된 멤버 이름의 배열을 가져오거나 설정합니다.

Namespaces

이 스키마 개체에 사용할 XmlSerializerNamespaces를 가져오거나 설정합니다.

(다음에서 상속됨 XmlSchemaObject)
Parent

XmlSchemaObject의 부모를 가져오거나 설정합니다.

(다음에서 상속됨 XmlSchemaObject)
SourceUri

스키마를 로드한 파일의 소스 위치를 가져오거나 설정합니다.

(다음에서 상속됨 XmlSchemaObject)
UnhandledAttributes

현재 스키마의 대상 네임스페이스에 속하지 않는 정규화된 특성을 가져오거나 설정합니다.

(다음에서 상속됨 XmlSchemaAnnotated)

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상