XmlSchemaElement Sınıf

Tanım

element World Wide Web Konsorsiyumu (W3C) tarafından belirtilen XML Şeması öğesini temsil eder. Bu sınıf, tüm parçacık türleri için temel sınıftır ve xml belgesindeki bir öğeyi tanımlamak için kullanılır.

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
Devralma

Örnekler

Aşağıdaki örnek öğesini oluşturur 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

Yukarıdaki kod örneği için aşağıdaki XML dosyası kullanılır.

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

Açıklamalar

Önemli

  • Bilinmeyen veya güvenilmeyen kaynaklardan veya konumlardan gelen şemaları kullanmayın. Bunu yaptığınızda kodunuzun güvenliği tehlikeye girer.
  • XML şemaları (satır içi şemalar dahil) hizmet reddi saldırılarına karşı doğal olarak savunmasızdır; güvenilmeyen senaryolarda bunları kabul etmeyin.
  • Şema doğrulama hata iletileri ve özel durumlar, içerik modeli veya URI yolları hakkındaki hassas bilgileri şema dosyasının kullanımına sunabilir. Bu bilgileri güvenilmeyen arayanlara göstermemeye dikkat edin.

Oluşturucular

XmlSchemaElement()

XmlSchemaElement sınıfının yeni bir örneğini başlatır.

Özellikler

Annotation

Özelliğini alır veya ayarlar annotation .

(Devralındığı yer: XmlSchemaAnnotated)
Block

Türetme Block alır veya ayarlar.

BlockResolved

özelliğinin derleme sonrası değerini Block alır.

Constraints

öğesindeki kısıtlamalar koleksiyonunu alır.

DefaultValue

İçeriği basit bir türse veya öğesinin içeriği ise textOnlyöğesinin varsayılan değerini alır veya ayarlar.

ElementSchemaType

öğesinin veya SchemaTypeName değerlerine göre öğesinin SchemaType türünü temsil eden bir XmlSchemaType nesnesi alır.

ElementType
Kullanımdan kalktı.
Kullanımdan kalktı.
Kullanımdan kalktı.

Özelliğin derleme sonrası değerini ElementType tutan veya XmlSchemaElement öğesini temel alan XmlSchemaElement ortak dil çalışma zamanı (CLR) nesnesini alır.

Final

Başka türetmelere izin verilmediğini belirtmek için özelliğini alır veya ayarlar Final .

FinalResolved

özelliğinin derleme sonrası değerini Final alır.

FixedValue

Sabit değeri alır veya ayarlar.

Form

Öğesinin formunu alır veya ayarlar.

Id

Dize kimliğini alır veya ayarlar.

(Devralındığı yer: XmlSchemaAnnotated)
IsAbstract

Öğenin bir örnek belgesinde kullanılıp kullanılamayabileceğini belirtmek için bilgileri alır veya ayarlar.

IsNillable

Örnek verilerinde olup olmadığını xsi:nil belirten bilgileri alır veya ayarlar. öğesine açık bir nil değeri atanabilir olup olmadığını gösterir.

LineNumber

Öğenin başvurduğu schema dosyadaki satır numarasını alır veya ayarlar.

(Devralındığı yer: XmlSchemaObject)
LinePosition

Öğenin başvurduğu schema dosyadaki satır konumunu alır veya ayarlar.

(Devralındığı yer: XmlSchemaObject)
MaxOccurs

Parçacığın oluşabileceği maksimum sayısı alır veya ayarlar.

(Devralındığı yer: XmlSchemaParticle)
MaxOccursString

Sayıyı dize değeri olarak alır veya ayarlar. Parçacığın oluşabileceği maksimum sayı.

(Devralındığı yer: XmlSchemaParticle)
MinOccurs

Parçacığın oluşabileceği minimum sayısını alır veya ayarlar.

(Devralındığı yer: XmlSchemaParticle)
MinOccursString

Sayıyı dize değeri olarak alır veya ayarlar. Parçacığın oluşabileceği minimum sayıdır.

(Devralındığı yer: XmlSchemaParticle)
Name

Öğesinin adını alır veya ayarlar.

Namespaces

Bu şema nesnesiyle kullanılacak öğesini XmlSerializerNamespaces alır veya ayarlar.

(Devralındığı yer: XmlSchemaObject)
Parent

Bu XmlSchemaObjectöğesinin üst öğesini alır veya ayarlar.

(Devralındığı yer: XmlSchemaObject)
QualifiedName

Verilen öğenin gerçek nitelenmiş adını alır.

RefName

Bu şemada bildirilen bir öğenin başvuru adını (veya belirtilen ad alanı tarafından belirtilen başka bir şemayı) alır veya ayarlar.

SchemaType

Öğesinin türünü alır veya ayarlar. Bu karmaşık bir tür veya basit bir tür olabilir.

SchemaTypeName

Bu şemada veya belirtilen ad alanı tarafından belirtilen başka bir şemada tanımlanan yerleşik veri türünün adını alır veya ayarlar.

SourceUri

Şemayı yükleyen dosyanın kaynak konumunu alır veya ayarlar.

(Devralındığı yer: XmlSchemaObject)
SubstitutionGroup

Bu öğe tarafından değiştirilen bir öğenin adını alır veya ayarlar.

UnhandledAttributes

Geçerli şemanın hedef ad alanına ait olmayan nitelikli öznitelikleri alır veya ayarlar.

(Devralındığı yer: XmlSchemaAnnotated)

Yöntemler

Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetType()

Type Geçerli örneğini alır.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

(Devralındığı yer: Object)
ToString()

Geçerli nesneyi temsil eden dizeyi döndürür.

(Devralındığı yer: Object)

Şunlara uygulanır