XmlSchemaAttribute Kelas
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
attribute Mewakili elemen dari Skema XML seperti yang ditentukan oleh World Wide Web Consortium (W3C). Atribut menyediakan informasi tambahan untuk elemen dokumen lainnya. Tag atribut disarangkan di antara tag elemen dokumen untuk skema. Dokumen XML menampilkan atribut sebagai item bernama dalam tag pembuka elemen.
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
- Warisan
Contoh
Contoh berikut membuat attribute elemen .
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
File XML berikut dibuat untuk contoh kode sebelumnya.
<?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>
Keterangan
Deklarasi atribut dapat hadir sebagai elemen turunan dari schema elemen (memiliki cakupan global) atau dalam definisi jenis kompleks. Untuk jenis kompleks, deklarasi atribut dapat hadir sebagai deklarasi atau referensi lokal ke atribut dengan cakupan global. Baik deklarasi atribut global maupun lokal memiliki atribut jenis opsional yang mengacu pada jenis sederhana yang ada. Jika atribut jenis opsional tidak digunakan, deklarasi atribut (global atau lokal) harus menentukan jenis sederhana lokal.
Konstruktor
| Nama | Deskripsi |
|---|---|
| XmlSchemaAttribute() |
Menginisialisasi instans baru dari kelas XmlSchemaAttribute. |
Properti
| Nama | Deskripsi |
|---|---|
| Annotation |
Mendapatkan atau mengatur |
| AttributeSchemaType |
Mendapatkan objek yang XmlSchemaSimpleType mewakili jenis atribut berdasarkan SchemaType atau SchemaTypeName atribut . |
| AttributeType |
Kedaluwarsa.
Kedaluwarsa.
Kedaluwarsa.
Mendapatkan objek runtime bahasa umum (CLR) berdasarkan SchemaType atau SchemaTypeName atribut yang menyimpan nilai |
| DefaultValue |
Mendapatkan atau mengatur nilai default untuk atribut . |
| FixedValue |
Mendapatkan atau menetapkan nilai tetap untuk atribut . |
| Form |
Mendapatkan atau mengatur formulir untuk atribut . |
| Id |
Mendapatkan atau mengatur id string. (Diperoleh dari XmlSchemaAnnotated) |
| LineNumber |
Mendapatkan atau mengatur nomor baris dalam file yang |
| LinePosition |
Mendapatkan atau mengatur posisi baris dalam file yang |
| Name |
Mendapatkan atau mengatur nama atribut. |
| Namespaces |
Mendapatkan atau mengatur XmlSerializerNamespaces untuk digunakan dengan objek skema ini. (Diperoleh dari XmlSchemaObject) |
| Parent |
Mendapatkan atau mengatur induk dari ini XmlSchemaObject. (Diperoleh dari XmlSchemaObject) |
| QualifiedName |
Mendapatkan nama yang memenuhi syarat untuk atribut . |
| RefName |
Mendapatkan atau menetapkan nama atribut yang dideklarasikan dalam skema ini (atau skema lain yang ditunjukkan oleh namespace yang ditentukan). |
| SchemaType |
Mendapatkan atau mengatur jenis atribut ke jenis sederhana. |
| SchemaTypeName |
Mendapatkan atau mengatur nama jenis sederhana yang ditentukan dalam skema ini (atau skema lain yang ditunjukkan oleh namespace yang ditentukan). |
| SourceUri |
Mendapatkan atau mengatur lokasi sumber untuk file yang memuat skema. (Diperoleh dari XmlSchemaObject) |
| UnhandledAttributes |
Mendapatkan atau mengatur atribut yang memenuhi syarat yang bukan milik namespace target skema saat ini. (Diperoleh dari XmlSchemaAnnotated) |
| Use |
Mendapatkan atau mengatur informasi tentang cara atribut digunakan. |
Metode
| Nama | Deskripsi |
|---|---|
| Equals(Object) |
Menentukan apakah objek yang ditentukan sama dengan objek saat ini. (Diperoleh dari Object) |
| GetHashCode() |
Berfungsi sebagai fungsi hash default. (Diperoleh dari Object) |
| GetType() |
Mendapatkan Type instans saat ini. (Diperoleh dari Object) |
| MemberwiseClone() |
Membuat salinan dangkal dari Objectsaat ini. (Diperoleh dari Object) |
| ToString() |
Mengembalikan string yang mewakili objek saat ini. (Diperoleh dari Object) |