XmlSchemaAttribute クラス
アセンブリ: System.Xml (system.xml.dll 内)


属性宣言は、グローバル スコープを持つ schema 要素の子要素として、または複合型定義内に存在できます。複合型の場合、属性宣言は、ローカル宣言またはグローバル スコープを持つ属性の参照として存在できます。グローバル属性宣言およびローカル属性宣言は、両方とも既存の単純型を参照するオプションの型属性を持ちます。オプションの型属性を使用しない場合は、グローバル属性宣言またはローカル属性宣言でローカルな単純型を定義する必要があります。

Option Explicit On Option Strict On Imports System 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 'Main Public Shared Sub ValidationCallbackOne(ByVal sender As Object, ByVal args As ValidationEventArgs) Console.WriteLine(args.Message) End Sub 'ValidationCallbackOne End Class 'XMLSchemaExamples
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); } }
前述のコード例に対して生成される 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>

System.Xml.Schema.XmlSchemaObject
System.Xml.Schema.XmlSchemaAnnotated
System.Xml.Schema.XmlSchemaAttribute


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- XmlSchemaAttribute クラスのページへのリンク