XmlSchemaAttributeとは? わかりやすく解説

XmlSchemaAttribute クラス

W3C (World Wide Web Consortium) で指定された XML スキーマの attribute 要素を表します。属性とは、他のドキュメント要素の追加情報を提供するものです。属性タグは、スキーマのドキュメント要素のタグ間に入れ子にして指定します。XML ドキュメントでは、要素の開始タグの名前付き項目として属性が表示されます。

名前空間: System.Xml.Schema
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

Public Class XmlSchemaAttribute
    Inherits XmlSchemaAnnotated
Dim instance As XmlSchemaAttribute
public class XmlSchemaAttribute : XmlSchemaAnnotated
public ref class XmlSchemaAttribute : public
 XmlSchemaAnnotated
public class XmlSchemaAttribute extends XmlSchemaAnnotated
public class XmlSchemaAttribute extends
 XmlSchemaAnnotated
解説解説
使用例使用例

attribute 要素を作成する例を次に示します。

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.Object
   System.Xml.Schema.XmlSchemaObject
     System.Xml.Schema.XmlSchemaAnnotated
      System.Xml.Schema.XmlSchemaAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlSchemaAttribute メンバ
System.Xml.Schema 名前空間

XmlSchemaAttribute コンストラクタ


XmlSchemaAttribute プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Annotation  Annotation プロパティを取得または設定します。 ( XmlSchemaAnnotated から継承されます。)
パブリック プロパティ Id  文字列 ID を取得または設定します。 ( XmlSchemaAnnotated から継承されます。)
パブリック プロパティ LineNumber  schema 要素が参照するファイルの行番号を取得または設定します。 ( XmlSchemaObject から継承されます。)
パブリック プロパティ LinePosition  schema 要素が参照するファイルの行番号を取得または設定します。 ( XmlSchemaObject から継承されます。)
パブリック プロパティ Namespaces  このスキーマ オブジェクトと一緒に使用する XmlSerializerNamespaces を取得または設定します。 ( XmlSchemaObject から継承されます。)
パブリック プロパティ Parent  この XmlSchemaObject の親を取得または設定します。 ( XmlSchemaObject から継承されます。)
パブリック プロパティ SourceUri  スキーマを読み込んだファイルのソース位置を取得または設定します。 ( XmlSchemaObject から継承されます。)
パブリック プロパティ UnhandledAttributes  現在のスキーマのターゲット名前空間に属さない、修飾された属性を取得または設定します。 ( XmlSchemaAnnotated から継承されます。)
パブリック プロパティ Use 属性がどのように使用されたかに関する情報を取得または設定します。
参照参照

関連項目

XmlSchemaAttribute クラス
System.Xml.Schema 名前空間

XmlSchemaAttribute メソッド


XmlSchemaAttribute メンバ

W3C (World Wide Web Consortium) で指定された XML スキーマの attribute 要素を表します。属性とは、他のドキュメント要素の追加情報を提供するものです。属性タグは、スキーマのドキュメント要素のタグ間に入れ子にして指定します。XML ドキュメントでは、要素の開始タグの名前付き項目として属性が表示されます。

XmlSchemaAttribute データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド XmlSchemaAttribute XmlSchemaAttribute クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Annotation  Annotation プロパティを取得または設定します。(XmlSchemaAnnotated から継承されます。)
パブリック プロパティ Id  文字列 ID を取得または設定します。(XmlSchemaAnnotated から継承されます。)
パブリック プロパティ LineNumber  schema 要素が参照するファイルの行番号を取得または設定します。(XmlSchemaObject から継承されます。)
パブリック プロパティ LinePosition  schema 要素が参照するファイルの行番号を取得または設定します。(XmlSchemaObject から継承されます。)
パブリック プロパティ Namespaces  このスキーマ オブジェクトと一緒に使用する XmlSerializerNamespaces を取得または設定します。(XmlSchemaObject から継承されます。)
パブリック プロパティ Parent  この XmlSchemaObject の親を取得または設定します。(XmlSchemaObject から継承されます。)
パブリック プロパティ SourceUri  スキーマを読み込んだファイルのソース位置を取得または設定します。(XmlSchemaObject から継承されます。)
パブリック プロパティ UnhandledAttributes  現在のスキーマのターゲット名前空間に属さない、修飾された属性を取得または設定します。(XmlSchemaAnnotated から継承されます。)
パブリック プロパティ Use 属性がどのように使用されたかに関する情報を取得または設定します。
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

XmlSchemaAttribute クラス
System.Xml.Schema 名前空間



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「XmlSchemaAttribute」の関連用語

XmlSchemaAttributeのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



XmlSchemaAttributeのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS