XmlSchemaAttribute Třída

Definice

attribute Představuje element ze schématu XML určeného konsorciem W3C (World Wide Web Consortium). Atributy poskytují další informace o dalších prvcích dokumentu. Značka atributu je vnořená mezi značky elementu dokumentu pro schéma. Dokument XML zobrazí atributy jako pojmenované položky v počáteční značce elementu.

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
Dědičnost

Příklady

Následující příklad vytvoří attribute 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: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

Pro předchozí příklad kódu se vygeneruje následující soubor XML.


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

Poznámky

Deklarace atributů mohou být přítomny jako podřízené prvky elementu schema (s globálním oborem) nebo v rámci definic komplexních typů. Pro komplexní typy atribut deklarace může být k dispozici jako místní prohlášení nebo odkazy na atributy s globálním oboru. Deklarace globálního i místního atributu mají volitelný atribut typu, který odkazuje na existující jednoduchý typ. Pokud se nepovinný atribut typu nepoužívá, musí deklarace atributu (globální nebo místní) definovat místní jednoduchý typ.

Konstruktory

XmlSchemaAttribute()

Inicializuje novou instanci XmlSchemaAttribute třídy.

Vlastnosti

Annotation

Získá nebo nastaví annotation vlastnost.

(Zděděno od XmlSchemaAnnotated)
AttributeSchemaType

XmlSchemaSimpleType Získá objekt představující typ atributu na SchemaType základě nebo SchemaTypeName atributu.

AttributeType
Zastaralé.
Zastaralé.
Zastaralé.

Získá common language runtime (CLR) objektu na SchemaType základě nebo SchemaTypeName atributu, který obsahuje hodnotu post-kompilace AttributeType vlastnosti.

DefaultValue

Získá nebo nastaví výchozí hodnotu atributu.

FixedValue

Získá nebo nastaví pevnou hodnotu atributu.

Form

Získá nebo nastaví formulář pro atribut.

Id

Získá nebo nastaví ID řetězce.

(Zděděno od XmlSchemaAnnotated)
LineNumber

Získá nebo nastaví číslo řádku v souboru, na který schema prvek odkazuje.

(Zděděno od XmlSchemaObject)
LinePosition

Získá nebo nastaví pozici řádku v souboru, na který schema prvek odkazuje.

(Zděděno od XmlSchemaObject)
Name

Získá nebo nastaví název atributu.

Namespaces

Získá nebo nastaví XmlSerializerNamespaces na použití s tímto objektem schématu.

(Zděděno od XmlSchemaObject)
Parent

Získá nebo nastaví nadřazený objekt tohoto XmlSchemaObjectobjektu .

(Zděděno od XmlSchemaObject)
QualifiedName

Získá kvalifikovaný název atributu.

RefName

Získá nebo nastaví název atributu deklarovaného v tomto schématu (nebo jiném schématu označeném zadaným oborem názvů).

SchemaType

Získá nebo nastaví typ atributu na jednoduchý typ.

SchemaTypeName

Získá nebo nastaví název jednoduchého typu definovaného v tomto schématu (nebo jiném schématu označeném zadaným oborem názvů).

SourceUri

Získá nebo nastaví zdrojové umístění pro soubor, který načetl schéma.

(Zděděno od XmlSchemaObject)
UnhandledAttributes

Získá nebo nastaví kvalifikované atributy, které nepatří do cílového oboru názvů aktuálního schématu.

(Zděděno od XmlSchemaAnnotated)
Use

Získá nebo nastaví informace o způsobu použití atributu.

Metody

Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.

(Zděděno od Object)
GetHashCode()

Slouží jako výchozí hashovací funkce.

(Zděděno od Object)
GetType()

Získá aktuální Type instanci.

(Zděděno od Object)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Objectsouboru .

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Platí pro