XmlSchemaAttribute Klasa

Definicja

attribute Reprezentuje element ze schematu XML określony przez World Wide Web Consortium (W3C). Atrybuty udostępniają dodatkowe informacje dla innych elementów dokumentu. Tag atrybutu jest zagnieżdżony między tagami elementu dokumentu dla schematu. Dokument XML wyświetla atrybuty jako nazwane elementy w tagu otwierania 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
Dziedziczenie

Przykłady

Poniższy przykład tworzy 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

Poniższy plik XML jest generowany dla poprzedniego przykładu kodu.


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

Uwagi

Deklaracje atrybutów mogą być obecne jako elementy schema podrzędne elementu (o zakresie globalnym) lub w definicjach typów złożonych. W przypadku typów złożonych deklaracje atrybutów mogą być obecne jako deklaracje lokalne lub odwołania do atrybutów z zakresem globalnym. Zarówno deklaracje atrybutów globalnych, jak i lokalnych mają opcjonalny atrybut typu odwołujący się do istniejącego prostego typu. Jeśli opcjonalny atrybut typu nie jest używany, deklaracja atrybutu (globalna lub lokalna) musi zdefiniować lokalny typ prosty.

Konstruktory

XmlSchemaAttribute()

Inicjuje nowe wystąpienie klasy XmlSchemaAttribute.

Właściwości

Annotation

Pobiera lub ustawia annotation właściwość.

(Odziedziczone po XmlSchemaAnnotated)
AttributeSchemaType

XmlSchemaSimpleType Pobiera obiekt reprezentujący typ atrybutu na SchemaType podstawie lub SchemaTypeName atrybutu.

AttributeType
Nieaktualne.
Nieaktualne.
Nieaktualne.

Pobiera obiekt środowiska uruchomieniowego języka wspólnego (CLR) na SchemaType podstawie atrybutu lub SchemaTypeName , który zawiera wartość AttributeType po kompilacji właściwości.

DefaultValue

Pobiera lub ustawia wartość domyślną atrybutu.

FixedValue

Pobiera lub ustawia stałą wartość atrybutu.

Form

Pobiera lub ustawia formularz atrybutu.

Id

Pobiera lub ustawia identyfikator ciągu.

(Odziedziczone po XmlSchemaAnnotated)
LineNumber

Pobiera lub ustawia numer wiersza w pliku, do którego schema odwołuje się element.

(Odziedziczone po XmlSchemaObject)
LinePosition

Pobiera lub ustawia położenie wiersza w pliku, do którego schema odwołuje się element.

(Odziedziczone po XmlSchemaObject)
Name

Pobiera lub ustawia nazwę atrybutu.

Namespaces

Pobiera lub ustawia XmlSerializerNamespaces obiekt do użycia z tym obiektem schematu.

(Odziedziczone po XmlSchemaObject)
Parent

Pobiera lub ustawia element nadrzędny tego XmlSchemaObjectobiektu .

(Odziedziczone po XmlSchemaObject)
QualifiedName

Pobiera kwalifikowaną nazwę atrybutu.

RefName

Pobiera lub ustawia nazwę atrybutu zadeklarowanego w tym schemacie (lub inny schemat wskazany przez określoną przestrzeń nazw).

SchemaType

Pobiera lub ustawia typ atrybutu na prosty typ.

SchemaTypeName

Pobiera lub ustawia nazwę prostego typu zdefiniowanego w tym schemacie (lub inny schemat wskazany przez określoną przestrzeń nazw).

SourceUri

Pobiera lub ustawia lokalizację źródłową pliku, który załadował schemat.

(Odziedziczone po XmlSchemaObject)
UnhandledAttributes

Pobiera lub ustawia kwalifikowane atrybuty, które nie należą do docelowej przestrzeni nazw bieżącego schematu.

(Odziedziczone po XmlSchemaAnnotated)
Use

Pobiera lub ustawia informacje o sposobie użycia atrybutu.

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy