XmlSchema 클래스

정의

W3C(World Wide Web 컨소시엄) XML 스키마 파트 1: 구조XML 스키마 파트 2: 데이터 형식에서 지정한 XML 스키마의 메모리 내 표현입니다.

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

예제

다음 예제에서는 스키마 정의를 만듭니다.

#using <mscorlib.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::Xml;
using namespace System::Xml::Schema;

class XmlSchemaExamples
{
public:
    static void Main()
    {

        XmlSchema^ schema = gcnew XmlSchema();

        // <xs:element name="cat" type="xs:string"/>
        XmlSchemaElement^ elementCat = gcnew XmlSchemaElement();
        schema->Items->Add(elementCat);
        elementCat->Name = "cat";
        elementCat->SchemaTypeName = gcnew XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

        // <xs:element name="dog" type="xs:string"/>
        XmlSchemaElement^ elementDog = gcnew XmlSchemaElement();
        schema->Items->Add(elementDog);
        elementDog->Name = "dog";
        elementDog->SchemaTypeName = gcnew XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

        // <xs:element name="redDog" substitutionGroup="dog" />
        XmlSchemaElement^ elementRedDog = gcnew XmlSchemaElement();
        schema->Items->Add(elementRedDog);
        elementRedDog->Name = "redDog";
        elementRedDog->SubstitutionGroup = gcnew XmlQualifiedName("dog");

        // <xs:element name="brownDog" substitutionGroup ="dog" />
        XmlSchemaElement^ elementBrownDog = gcnew XmlSchemaElement();
        schema->Items->Add(elementBrownDog);
        elementBrownDog->Name = "brownDog";
        elementBrownDog->SubstitutionGroup = gcnew XmlQualifiedName("dog");


        // <xs:element name="pets">
        XmlSchemaElement^ elementPets = gcnew XmlSchemaElement();
        schema->Items->Add(elementPets);
        elementPets->Name = "pets";

        // <xs:complexType>
        XmlSchemaComplexType^ complexType = gcnew XmlSchemaComplexType();
        elementPets->SchemaType = complexType;

        // <xs:choice minOccurs="0" maxOccurs="unbounded">
        XmlSchemaChoice^ choice = gcnew XmlSchemaChoice();
        complexType->Particle = choice;
        choice->MinOccurs = 0;
        choice->MaxOccursString = "unbounded";

        // <xs:element ref="cat"/>
        XmlSchemaElement^ catRef = gcnew XmlSchemaElement();
        choice->Items->Add(catRef);
        catRef->RefName = gcnew XmlQualifiedName("cat");

        // <xs:element ref="dog"/>
        XmlSchemaElement^ dogRef = gcnew XmlSchemaElement();
        choice->Items->Add(dogRef);
        dogRef->RefName = gcnew XmlQualifiedName("dog");

        XmlSchemaSet^ schemaSet = gcnew XmlSchemaSet();
        schemaSet->ValidationEventHandler += gcnew ValidationEventHandler(ValidationCallbackOne);
        schemaSet->Add(schema);
        schemaSet->Compile();

        XmlSchema^ compiledSchema;

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

    static void ValidationCallbackOne(Object^ sender, ValidationEventArgs^ args)
    {
        Console::WriteLine(args->Message);
    }
};

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:element name="cat" type="xs:string"/>
        XmlSchemaElement elementCat = new XmlSchemaElement();
        schema.Items.Add(elementCat);
        elementCat.Name = "cat";
        elementCat.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

        // <xs:element name="dog" type="xs:string"/>
        XmlSchemaElement elementDog = new XmlSchemaElement();
        schema.Items.Add(elementDog);
        elementDog.Name = "dog";
        elementDog.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

        // <xs:element name="redDog" substitutionGroup="dog" />
        XmlSchemaElement elementRedDog = new XmlSchemaElement();
        schema.Items.Add(elementRedDog);
        elementRedDog.Name = "redDog";
        elementRedDog.SubstitutionGroup = new XmlQualifiedName("dog");

        // <xs:element name="brownDog" substitutionGroup ="dog" />
        XmlSchemaElement elementBrownDog = new XmlSchemaElement();
        schema.Items.Add(elementBrownDog);
        elementBrownDog.Name = "brownDog";
        elementBrownDog.SubstitutionGroup = new XmlQualifiedName("dog");

        // <xs:element name="pets">
        XmlSchemaElement elementPets = new XmlSchemaElement();
        schema.Items.Add(elementPets);
        elementPets.Name = "pets";

        // <xs:complexType>
        XmlSchemaComplexType complexType = new XmlSchemaComplexType();
        elementPets.SchemaType = complexType;

        // <xs:choice minOccurs="0" maxOccurs="unbounded">
        XmlSchemaChoice choice = new XmlSchemaChoice();
        complexType.Particle = choice;
        choice.MinOccurs = 0;
        choice.MaxOccursString = "unbounded";

        // <xs:element ref="cat"/>
        XmlSchemaElement catRef = new XmlSchemaElement();
        choice.Items.Add(catRef);
        catRef.RefName = new XmlQualifiedName("cat");

        // <xs:element ref="dog"/>
        XmlSchemaElement dogRef = new XmlSchemaElement();
        choice.Items.Add(dogRef);
        dogRef.RefName = new XmlQualifiedName("dog");

        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);
    }
}
Option Explicit On
Option Strict On

Imports System.Xml
Imports System.Xml.Schema

Class XMLSchemaExamples
    Public Shared Sub Main()
        Dim schema As New XmlSchema()

        ' <xs:element name="cat" type="xs:string"/>
        Dim elementCat As New XmlSchemaElement()
        schema.Items.Add(elementCat)
        elementCat.Name = "cat"
        elementCat.SchemaTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")

        ' <xs:element name="dog" type="xs:string"/>
        Dim elementDog As New XmlSchemaElement()
        schema.Items.Add(elementDog)
        elementDog.Name = "dog"
        elementDog.SchemaTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")

        ' <xs:element name="redDog" substitutionGroup="dog" />
        Dim elementRedDog As New XmlSchemaElement()
        schema.Items.Add(elementRedDog)
        elementRedDog.Name = "redDog"
        elementRedDog.SubstitutionGroup = New XmlQualifiedName("dog")

        ' <xs:element name="brownDog" substitutionGroup ="dog" />
        Dim elementBrownDog As New XmlSchemaElement()
        schema.Items.Add(elementBrownDog)
        elementBrownDog.Name = "brownDog"
        elementBrownDog.SubstitutionGroup = New XmlQualifiedName("dog")

        ' <xs:element name="pets">
        Dim elementPets As New XmlSchemaElement()
        schema.Items.Add(elementPets)
        elementPets.Name = "pets"

        ' <xs:complexType>
        Dim complexType As New XmlSchemaComplexType()
        elementPets.SchemaType = complexType

        ' <xs:choice minOccurs="0" maxOccurs="unbounded">
        Dim choice As New XmlSchemaChoice()
        complexType.Particle = choice
        choice.MinOccurs = 0
        choice.MaxOccursString = "unbounded"

        ' <xs:element ref="cat"/>
        Dim catRef As New XmlSchemaElement()
        choice.Items.Add(catRef)
        catRef.RefName = New XmlQualifiedName("cat")

        ' <xs:element ref="dog"/>
        Dim dogRef As New XmlSchemaElement()
        choice.Items.Add(dogRef)
        dogRef.RefName = New XmlQualifiedName("dog")

        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:element name="cat" type="xs:string"/>
    <xs:element name="dog" type="xs:string"/>
    <xs:element name="redDog" type="xs:string" substitutionGroup="dog"/>
    <xs:element name="brownDog" type="xs:string" substitutionGroup ="dog" />

    <xs:element name="pets">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element ref="cat"/>
          <xs:element ref="dog"/>
        </xs:choice>
      </xs:complexType>
    </xs:element>
</xs:schema>

설명

중요

  • 알 수 없거나 신뢰할 수 없는 출처 또는 위치에서 스키마를 사용 하지 마세요. 이렇게 하면 코드의 보안이 손상 됩니다.
  • XML 스키마 (인라인 스키마 포함)는 서비스 거부 공격;에 기본적으로 취약 이러한 신뢰할 수 없는 시나리오에서 허용 하지 않습니다.
  • 클래스와 같은 XmlSchemaException 클래스를 사용한 XmlSchema 결과로 발생한 예외에는 신뢰할 수 없는 시나리오에서 노출되어서는 안 되는 중요한 정보가 포함될 수 있습니다. 예를 들어, 속성 XmlSchemaExceptionSourceUri 예외를 발생시킨 스키마 파일에 대한 URI 경로를 반환합니다. SourceUri 신뢰할 수 없는 시나리오에서는 속성을 노출해서는 안 됩니다. 이 중요한 정보가 신뢰할 수 없는 시나리오에서 노출되지 않도록 예외를 올바르게 처리해야 합니다.

생성자

XmlSchema()

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

필드

InstanceNamespace

XML 스키마 인스턴스 네임스페이스입니다. 이 필드는 상수입니다.

Namespace

XML 스키마 네임스페이스입니다. 이 필드는 상수입니다.

속성

AttributeFormDefault

스키마의 대상 네임스페이스에서 선언된 특성에 해당하는 폼을 가져오거나 설정합니다.

AttributeGroups

스키마에 있는 모든 전역 특성 그룹의 스키마 컴파일 이후 값을 가져옵니다.

Attributes

스키마에 있는 모든 특성에 대한 스키마 컴파일 이후 값을 가져옵니다.

BlockDefault

스키마의 blockDefault에 포함된 요소 및 복합 형식에 대한 block 특성의 기본값을 설정하는 targetNamespace 특성을 가져오거나 설정합니다.

ElementFormDefault

스키마의 대상 네임스페이스에서 선언된 요소에 해당하는 폼을 가져오거나 설정합니다.

Elements

스키마에 있는 모든 요소에 대한 스키마 컴파일 이후 값을 가져옵니다.

FinalDefault

스키마의 대상 네임스페이스에 포함된 요소 및 복합 형식에 대한 finalDefault 특성의 기본값을 설정하는 final 특성을 가져오거나 설정합니다.

Groups

스키마에 있는 모든 그룹의 스키마 컴파일 이후 값을 가져옵니다.

Id

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

Includes

포함된 스키마와 가져온 스키마의 컬렉션을 가져옵니다.

IsCompiled

스키마가 컴파일되었는지 여부를 나타냅니다.

Items

스키마에 있는 스키마 요소의 컬렉션을 가져오며 schema 요소 수준에서 새 요소 형식을 추가하는 데 사용됩니다.

LineNumber

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

(다음에서 상속됨 XmlSchemaObject)
LinePosition

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

(다음에서 상속됨 XmlSchemaObject)
Namespaces

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

(다음에서 상속됨 XmlSchemaObject)
Notations

스키마에 있는 모든 표기법에 대한 스키마 컴파일 이후 값을 가져옵니다.

Parent

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

(다음에서 상속됨 XmlSchemaObject)
SchemaTypes

스키마에 있는 모든 스키마 형식의 스키마 컴파일 이후 값을 가져옵니다.

SourceUri

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

(다음에서 상속됨 XmlSchemaObject)
TargetNamespace

스키마 대상 네임스페이스의 URI(Uniform Resource Identifier)를 가져오거나 설정합니다.

UnhandledAttributes

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

Version

스키마의 버전을 가져오거나 설정합니다.

메서드

Compile(ValidationEventHandler)
사용되지 않습니다.
사용되지 않습니다.
사용되지 않습니다.

유효성 검사를 위해 XML SOM(스키마 개체 모델)을 스키마 정보로 컴파일합니다. 프로그래밍에 의해 생성된 SOM의 구문 및 의미론 구조를 검사하는 데 사용됩니다. 의미론 유효성 검사는 컴파일 과정에서 수행됩니다.

Compile(ValidationEventHandler, XmlResolver)
사용되지 않습니다.
사용되지 않습니다.
사용되지 않습니다.

유효성 검사를 위해 XML SOM(스키마 개체 모델)을 스키마 정보로 컴파일합니다. 프로그래밍에 의해 생성된 SOM의 구문 및 의미론 구조를 검사하는 데 사용됩니다. 의미론 유효성 검사는 컴파일 과정에서 수행됩니다.

Equals(Object)

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

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

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

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

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

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

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

(다음에서 상속됨 Object)
Read(Stream, ValidationEventHandler)

제공된 스트림에서 XML 스키마를 읽습니다.

Read(TextReader, ValidationEventHandler)

제공된 TextReader에서 XML 스키마를 읽습니다.

Read(XmlReader, ValidationEventHandler)

제공된 XmlReader에서 XML 스키마를 읽습니다.

ToString()

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

(다음에서 상속됨 Object)
Write(Stream)

제공된 데이터 스트림에 XML 스키마를 작성합니다.

Write(Stream, XmlNamespaceManager)

지정된 Stream를 사용하여 제공된 XmlNamespaceManager에 XML 스키마를 씁니다.

Write(TextWriter)

제공된 TextWriter에 XML 스키마를 작성합니다.

Write(TextWriter, XmlNamespaceManager)

제공된 TextWriter에 XML 스키마를 작성합니다.

Write(XmlWriter)

제공된 XmlWriter에 XML 스키마를 작성합니다.

Write(XmlWriter, XmlNamespaceManager)

제공된 XmlWriter에 XML 스키마를 작성합니다.

적용 대상

추가 정보