XmlSchemaElement 클래스

정의

W3C(World Wide Web 컨소시엄)에서 지정한 대로 XML 스키마의 element 요소를 나타냅니다. 이 클래스는 모든 파티클 형식의 기본 클래스이며 XML 문서에서 요소를 설명하는 데 사용됩니다.

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

예제

다음 예제에서는 요소를 만듭니다 element .

#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="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="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="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="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);
    }
}
Imports System.Xml
Imports System.Xml.Schema

Class XMLSchemaExamples
    Public Shared Sub Main()

        Dim schema As New XmlSchema()

        ' <xs:element name="cat" type="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="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" substitutionGroup="dog" />
    <xs:element name="brownDog" 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 스키마 (인라인 스키마 포함)는 서비스 거부 공격;에 기본적으로 취약 이러한 신뢰할 수 없는 시나리오에서 허용 하지 않습니다.
  • 스키마 유효성 검사 오류 메시지 및 예외 콘텐츠 모델 또는 스키마 파일에 URI 경로 대 한 중요 한 정보를 노출할 수 있습니다. 신뢰할 수 없는 호출자에 게이 정보를 노출 하지 않도록 주의 해야 합니다.

생성자

XmlSchemaElement()

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

속성

Annotation

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

(다음에서 상속됨 XmlSchemaAnnotated)
Block

Block 파생을 가져오거나 설정합니다.

BlockResolved

Block 속성의 컴파일 이후 값을 가져옵니다.

Constraints

요소에 대한 제약 조건의 컬렉션을 가져옵니다.

DefaultValue

요소의 내용이 단순 형식이거나 textOnly인 경우 해당 요소의 기본값을 가져오거나 설정합니다.

ElementSchemaType

요소의 XmlSchemaType 또는 SchemaType 값에 따라 요소의 형식을 나타내는 SchemaTypeName 개체를 가져옵니다.

ElementType
사용되지 않습니다.
사용되지 않습니다.
사용되지 않습니다.

ElementType 속성의 컴파일 이후 값을 보유하는 요소의 XmlSchemaElement 또는 XmlSchemaElement에 기반하는 CLR(공용 언어 런타임) 개체를 가져옵니다.

Final

추가 파생이 허용되지 않음을 나타내는 Final 속성을 가져오거나 설정합니다.

FinalResolved

Final 속성의 컴파일 이후 값을 가져옵니다.

FixedValue

고정 값을 가져오거나 설정합니다.

Form

요소에 대한 폼을 가져오거나 설정합니다.

Id

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

(다음에서 상속됨 XmlSchemaAnnotated)
IsAbstract

요소를 인스턴스 문서에서 사용할 수 있는지 여부를 나타내는 정보를 가져오거나 설정합니다.

IsNillable

xsi:nil을 인스턴스 데이터에서 사용할 수 있는지 여부를 나타내는 정보를 가져오거나 설정합니다. 명시적 nil 값을 요소에 할당할 수 있는지 여부를 나타냅니다.

LineNumber

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

(다음에서 상속됨 XmlSchemaObject)
LinePosition

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

(다음에서 상속됨 XmlSchemaObject)
MaxOccurs

파티클이 발생할 수 있는 최대 횟수를 가져오거나 설정합니다.

(다음에서 상속됨 XmlSchemaParticle)
MaxOccursString

숫자를 문자열 값으로 가져오거나 설정합니다. 파티클이 발생할 수 있는 최대 횟수입니다.

(다음에서 상속됨 XmlSchemaParticle)
MinOccurs

파티클이 발생할 수 있는 최소 횟수를 가져오거나 설정합니다.

(다음에서 상속됨 XmlSchemaParticle)
MinOccursString

숫자를 문자열 값으로 가져오거나 설정합니다. 파티클이 발생할 수 있는 최소 횟수입니다.

(다음에서 상속됨 XmlSchemaParticle)
Name

요소의 이름을 가져오거나 설정합니다.

Namespaces

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

(다음에서 상속됨 XmlSchemaObject)
Parent

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

(다음에서 상속됨 XmlSchemaObject)
QualifiedName

지정된 요소의 실제 정규화된 이름을 가져옵니다.

RefName

이 스키마 또는 지정된 네임스페이스가 나타내는 다른 스키마에 선언된 요소의 참조 이름을 가져오거나 설정합니다.

SchemaType

요소의 형식을 가져오거나 설정합니다. 이 형식은 복합 형식이거나 단순 형식일 수 있습니다.

SchemaTypeName

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

SourceUri

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

(다음에서 상속됨 XmlSchemaObject)
SubstitutionGroup

이 요소로 대체할 요소의 이름을 가져오거나 설정합니다.

UnhandledAttributes

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

(다음에서 상속됨 XmlSchemaAnnotated)

메서드

Equals(Object)

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

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

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

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

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

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

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

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

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

(다음에서 상속됨 Object)

적용 대상