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

<AttributeUsageAttribute(AttributeTargets.Property Or AttributeTargets.Field Or AttributeTargets.Parameter Or AttributeTargets.ReturnValue, AllowMultiple:=False)> _ Public Class XmlNamespaceDeclarationsAttribute Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.ReturnValue, AllowMultiple=false)] public class XmlNamespaceDeclarationsAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Property|AttributeTargets::Field|AttributeTargets::Parameter|AttributeTargets::ReturnValue, AllowMultiple=false)] public ref class XmlNamespaceDeclarationsAttribute : public Attribute

XmlNamespaceDeclarationsAttribute 属性は、XmlSerializerNamespaces オブジェクトを返すフィールドまたはプロパティに対して、クラスで一度だけ適用できます。
XmlNamespaceDeclarationsAttribute によって、XML ドキュメントで使用するプリフィックスや関連付けられた名前空間を格納できます。たとえば、この属性の一般的な使用法の 1 つは、World Wide Web Consortium (www.w3.org) ドキュメントの「XML Language (XPath) Version 1.0」に定義されている XPath データを格納することです。XPath は、簡単に言えば、多くの名前空間プレフィックスやローカル名と他の構文を一緒に含む文字列です。
XPath 言語によって、プリフィックスをパスに関連付け、そのプリフィックスを XML ドキュメント内で使用できます。たとえば、次の "select" という名前の XML ドキュメントには、特定の URI (http://www.cohowinery.com/calendar/) に関連付けられたプリフィックス ("cal") が含まれています。要素は、XPath を含む "path" という名前の属性を格納しています。
<element name="select"> <complexType> <simpleContent> <attribute name="path" /> </simpleContent> </complexType> </element>
XmlNamespaceDeclarationsAttribute がない場合は、プレフィックスと名前空間の関連付けは失われます。
プリフィックスと名前空間 URI の関連付けを保持するには、次の C# コードと Visual Basic コードに示すように、XmlSerializerNamespaces オブジェクトを返すメンバを追加し、XmlNamespaceDeclarationsAttribute 属性をそのメンバに適用します。
// C# public class Select { [XmlAttribute] public string path; [XmlNamespaceDeclarations] public XmlSerializerNamespaces xmlns; } ' Visual Basic Public Class Select <XmlAttribute> Public path As String <XmlNamespaceDeclarations> Public xmlns As XmlSerializerNamespaces End Class
シリアル化すると、生成された XML ドキュメントのスキーマは、appinfo という名前の XML スキーマ定義 (XSD) 要素を格納します。さらに、この要素は、名前空間宣言を含むメンバの名前に設定される keepNamespaceDeclarations という名前のメタデータ要素を含みます。次の XML フラグメントはこのスキーマを示しています。
<xs:element name="select"> <xs:complexType> <xs:annotation> <xs:appinfo> <keepNamespaceDeclarations>xmlns</keepNamespaceDeclarations> </xs:appinfo> </xs:annotation> <xs:simpleContent> <xs:attribute name="path" /> </xs:simpleContent> </xs:complexType> </xs:element>
逆シリアル化では、xmlns フィールドには、すべての名前空間プレフィックスの定義を含む XmlSerializerNamespaces オブジェクトが格納されます。
シリアル化では、Add メソッドを使用して、プリフィックスと名前空間のペアを XmlSerializerNamespaces オブジェクトに追加できます。これを C# コードと Visual Basic コードで次に示します。
// C# using System; using System.IO; using System.Xml.Serialization; [XmlRoot("select")] public class Select { [XmlAttribute] public string xpath; [XmlNamespaceDeclarations] public XmlSerializerNamespaces xmlns; } public class Test { public static void Main(string[] args) { Select mySelect = new Select(); mySelect.xpath = "myNS:ref/@common:y"; mySelect.xmlns = new XmlSerializerNamespaces(); mySelect.xmlns.Add("MyNS", "myNS.tempuri.org"); mySelect.xmlns.Add("common", "common.tempuri.org"); XmlSerializer ser = new XmlSerializer(typeof(Select)); ser.Serialize(Console.Out, mySelect); } } // Output: // <?xml version="1.0" encoding="IBM437"?> // <select xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" // xmlns:common="common.tempuri.org" xmlns:MyNS="myNS.tempuri.org" xpath="myNS:ref/@common:y" /> ' Visual Basic Imports System Imports System.IO Imports System.Xml.Serialization <XmlRoot("select")> _ Public Class SelectPath <XmlAttribute> _ Public xpath As String <XmlNamespaceDeclarations> _ public xmlns As XmlSerializerNamespaces End Class Public Class Test Public Shared Sub Main() Dim mySelect As SelectPath = New SelectPath() mySelect.xpath = "myNS:ref/@common:y" mySelect.xmlns = New XmlSerializerNamespaces() mySelect.xmlns.Add("MyNS", "myNS.tempuri.org") mySelect.xmlns.Add("common", "common.tempuri.org") Dim ser As XmlSerializer = New XmlSerializer(mySelect.GetType) ser.Serialize(Console.Out, mySelect) End Sub End Class 'Output: ' <?xml version="1.0" encoding="IBM437"?> ' <select xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' xmlns:common="common.tempuri.org" xmlns:MyNS="myNS.tempuri.org" xpath="myNS:ref/@common:y" />
属性が適用されるメンバには、クラスで定義された XML 要素に属するプレフィックスと名前空間のペア以外は格納されないため注意が必要です。たとえば、次の XML ドキュメントでは、プレフィックス ペア "cal" だけがキャプチャされ、"x" プレフィックスはキャプチャされません。このデータを取得するには、XmlNamespaceDeclarationsAttribute を含むメンバを root 要素を表すクラスに追加します。

System.Attribute
System.Xml.Serialization.XmlNamespaceDeclarationsAttribute


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


XmlNamespaceDeclarationsAttribute コンストラクタ
アセンブリ: System.Xml (system.xml.dll 内)



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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


XmlNamespaceDeclarationsAttribute プロパティ
XmlNamespaceDeclarationsAttribute メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 ( Attribute から継承されます。) |
![]() | GetCustomAttribute | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 ( Attribute から継承されます。) |
![]() | GetCustomAttributes | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 ( Attribute から継承されます。) |
![]() | GetHashCode | このインスタンスのハッシュ コードを返します。 ( Attribute から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | IsDefaultAttribute | 派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 ( Attribute から継承されます。) |
![]() | IsDefined | オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 ( Attribute から継承されます。) |
![]() | Match | 派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 ( Attribute から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

XmlNamespaceDeclarationsAttribute メンバ
対象となるプロパティ、パラメータ、戻り値、またはクラス メンバに、XML ドキュメント内で使用する、名前空間に関連付けられたプレフィックスを含めることを指定します。
XmlNamespaceDeclarationsAttribute データ型で公開されるメンバを以下の表に示します。



名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 ( Attribute から継承されます。) |
![]() | GetCustomAttribute | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 (Attribute から継承されます。) |
![]() | GetCustomAttributes | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 (Attribute から継承されます。) |
![]() | GetHashCode | このインスタンスのハッシュ コードを返します。 (Attribute から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | IsDefaultAttribute | 派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 (Attribute から継承されます。) |
![]() | IsDefined | オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 (Attribute から継承されます。) |
![]() | Match | 派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 (Attribute から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

Weblioに収録されているすべての辞書からXmlNamespaceDeclarationsAttributeを検索する場合は、下記のリンクをクリックしてください。

- XmlNamespaceDeclarationsAttributeのページへのリンク