Share via


XmlSchemaAttribute Sınıf

Tanım

attribute World Wide Web Konsorsiyumu (W3C) tarafından belirtilen XML Şemasındaki öğeyi temsil eder. Öznitelikler, diğer belge öğeleri için ek bilgi sağlar. Öznitelik etiketi, şema için belge öğesinin etiketleri arasında iç içe yerleştirilmiştir. XML belgesi, bir öğenin açılış etiketinde öznitelikleri adlandırılmış öğeler olarak görüntüler.

public ref class XmlSchemaAttribute : System::Xml::Schema::XmlSchemaAnnotated
public class XmlSchemaAttribute : System.Xml.Schema.XmlSchemaAnnotated
type XmlSchemaAttribute = class
    inherit XmlSchemaAnnotated
Public Class XmlSchemaAttribute
Inherits XmlSchemaAnnotated
Devralma

Örnekler

Aşağıdaki örnek öğesini oluşturur attribute .

#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:attribute name="mybaseattribute">
        XmlSchemaAttribute^ attributeBase = gcnew XmlSchemaAttribute();
        schema->Items->Add(attributeBase);
        attributeBase->Name = "mybaseattribute";

        // <xs:simpleType>
        XmlSchemaSimpleType^ simpleType = gcnew XmlSchemaSimpleType();
        attributeBase->SchemaType = simpleType;

        // <xs:restriction base="integer">
        XmlSchemaSimpleTypeRestriction^ restriction = gcnew XmlSchemaSimpleTypeRestriction();
        simpleType->Content = restriction;
        restriction->BaseTypeName = gcnew XmlQualifiedName("integer", "http://www.w3.org/2001/XMLSchema");

        // <xs:maxInclusive value="1000"/>
        XmlSchemaMaxInclusiveFacet^ maxInclusive = gcnew XmlSchemaMaxInclusiveFacet();
        restriction->Facets->Add(maxInclusive);
        maxInclusive->Value = "1000";

        // <xs:complexType name="myComplexType">
        XmlSchemaComplexType^ complexType = gcnew XmlSchemaComplexType();
        schema->Items->Add(complexType);
        complexType->Name = "myComplexType";

        // <xs:attribute ref="mybaseattribute"/>
        XmlSchemaAttribute^ attributeBaseRef = gcnew XmlSchemaAttribute();
        complexType->Attributes->Add(attributeBaseRef);
        attributeBaseRef->RefName = gcnew XmlQualifiedName("mybaseattribute");

        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:attribute name="mybaseattribute">
        XmlSchemaAttribute attributeBase = new XmlSchemaAttribute();
        schema.Items.Add(attributeBase);
        attributeBase.Name = "mybaseattribute";

        // <xs:simpleType>
        XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType();
        attributeBase.SchemaType = simpleType;

        // <xs:restriction base="integer">
        XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
        simpleType.Content = restriction;
        restriction.BaseTypeName = new XmlQualifiedName("integer", "http://www.w3.org/2001/XMLSchema");

        // <xs:maxInclusive value="1000"/>
        XmlSchemaMaxInclusiveFacet maxInclusive = new XmlSchemaMaxInclusiveFacet();
        restriction.Facets.Add(maxInclusive);
        maxInclusive.Value = "1000";

        // <xs:complexType name="myComplexType">
        XmlSchemaComplexType complexType = new XmlSchemaComplexType();
        schema.Items.Add(complexType);
        complexType.Name = "myComplexType";

        // <xs:attribute ref="mybaseattribute"/>
        XmlSchemaAttribute attributeBaseRef = new XmlSchemaAttribute();
        complexType.Attributes.Add(attributeBaseRef);
        attributeBaseRef.RefName = new XmlQualifiedName("mybaseattribute");

        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:attribute name="mybaseattribute">
        Dim attributeBase As New XmlSchemaAttribute()
        schema.Items.Add(attributeBase)
        attributeBase.Name = "mybaseattribute"

        ' <xs:simpleType>
        Dim simpleType As New XmlSchemaSimpleType()
        attributeBase.SchemaType = simpleType

        ' <xs:restriction base="integer">
        Dim restriction As New XmlSchemaSimpleTypeRestriction()
        simpleType.Content = restriction
        restriction.BaseTypeName = New XmlQualifiedName("integer", "http://www.w3.org/2001/XMLSchema")

        ' <xs:maxInclusive value="1000"/>
        Dim maxInclusive As New XmlSchemaMaxInclusiveFacet()
        restriction.Facets.Add(maxInclusive)
        maxInclusive.Value = "1000"

        ' <xs:complexType name="myComplexType">
        Dim complexType As New XmlSchemaComplexType()
        schema.Items.Add(complexType)
        complexType.Name = "myComplexType"

        ' <xs:attribute ref="mybaseattribute"/>
        Dim attributeBaseRef As New XmlSchemaAttribute()
        complexType.Attributes.Add(attributeBaseRef)
        attributeBaseRef.RefName = New XmlQualifiedName("mybaseattribute")

        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ı oluşturulur.


<?xml version="1.0" encoding="IBM437"?>
<xs:schema  xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:attribute name="mybaseattribute">
        <xs:simpleType>
            <xs:restriction base="xs:integer">
                <xs:maxInclusive value="1000" />
            </xs:restriction>
        </xs:simpleType>
    </xs:attribute>
    <xs:complexType name="myComplexType">
        <xs:attribute ref="mybaseattribute" />
    </xs:complexType>
</xs:schema>

Açıklamalar

Öznitelik bildirimleri öğenin alt öğeleri schema olarak (genel kapsama sahip) veya karmaşık tür tanımları içinde bulunabilir. Karmaşık türler için öznitelik bildirimleri yerel bildirimler veya genel kapsama sahip özniteliklere başvurular olarak bulunabilir. Hem genel hem de yerel öznitelik bildirimleri, mevcut basit türe başvuran isteğe bağlı tür özniteliğine sahiptir. İsteğe bağlı tür özniteliği kullanılmıyorsa, öznitelik bildiriminin (genel veya yerel) yerel bir basit tür tanımlaması gerekir.

Oluşturucular

XmlSchemaAttribute()

XmlSchemaAttribute 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)
AttributeSchemaType

veya SchemaTypeName özniteliğini temel alan SchemaType özniteliğin türünü temsil eden bir XmlSchemaSimpleType nesne alır.

AttributeType
Geçersiz.
Geçersiz.
Geçersiz.

Ortak dil çalışma zamanı (CLR) nesnesini, özelliğin derleme sonrası değerini tutan veya SchemaTypeName özniteliğine AttributeType göre SchemaType alır.

DefaultValue

Özniteliğin varsayılan değerini alır veya ayarlar.

FixedValue

Özniteliğin sabit değerini alır veya ayarlar.

Form

Özniteliğin formunu alır veya ayarlar.

Id

Dize kimliğini alır veya ayarlar.

(Devralındığı yer: XmlSchemaAnnotated)
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)
Name

Özniteliğin 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

Özniteliğin tam adını alır.

RefName

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

SchemaType

Öznitelik türünü alır veya basit bir türe ayarlar.

SchemaTypeName

Bu şemada tanımlanan basit türün adını (veya belirtilen ad alanı tarafından belirtilen başka bir şemayı) alır veya ayarlar.

SourceUri

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

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

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

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

Özniteliğin nasıl kullanıldığıyla ilgili bilgileri alır veya ayarlar.

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