XmlElement.Attributes プロパティ
アセンブリ: System.Xml (system.xml.dll 内)

Public Overrides ReadOnly Property Attributes As XmlAttributeCollection
public override XmlAttributeCollection Attributes { get; }
public: virtual property XmlAttributeCollection^ Attributes { XmlAttributeCollection^ get () override; }
このノードの属性のリストを格納している XmlAttributeCollection。

Imports System Imports System.IO Imports System.Xml public class Sample public shared sub Main() Dim doc as XmlDocument = new XmlDocument() doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" & _ "<title>Pride And Prejudice</title>" & _ "</book>") Dim root as XmlElement = doc.DocumentElement ' Change the value of the first attribute. root.Attributes.Item(0).Value="fiction" Console.WriteLine("Display the modified XML...") Console.WriteLine(doc.InnerXml) end sub end class
using System; using System.IO; using System.Xml; public class Sample { public static void Main() { XmlDocument doc = new XmlDocument(); doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" + "<title>Pride And Prejudice</title>" + "</book>"); XmlElement root = doc.DocumentElement; // Change the value of the first attribute. root.Attributes[0].Value="fiction"; Console.WriteLine("Display the modified XML..."); Console.WriteLine(doc.InnerXml); } }
#using <System.Xml.dll> using namespace System; using namespace System::IO; using namespace System::Xml; int main() { XmlDocument^ doc = gcnew XmlDocument; doc->LoadXml( "<book genre='novel' ISBN='1-861001-57-5'><title>Pride And Prejudice</title></book>" ); XmlElement^ root = doc->DocumentElement; // Change the value of the first attribute. root->Attributes[ 0 ]->Value = "fiction"; Console::WriteLine( "Display the modified XML..." ); Console::WriteLine( doc->InnerXml ); }
import System.*; import System.IO.*; import System.Xml.*; public class Sample { public static void main(String[] args) { XmlDocument doc = new XmlDocument(); doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" + "<title>Pride And Prejudice</title>" + "</book>"); XmlElement root = doc.get_DocumentElement(); // Change the value of the first attribute. root.get_Attributes().Item(0).set_Value("fiction"); Console.WriteLine("Display the modified XML..."); Console.WriteLine(doc.get_InnerXml()); } //main } //Sample

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


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


XmlElementAttributes は、XmlAttributes クラスの XmlElements プロパティによって返されます。XmlAttributeOverrides クラスと XmlAttributes クラスを使用して、XmlSerializer がクラスをシリアル化する既定の方法をオーバーライドできます。

Transportation クラスをシリアル化する例を次に示します。この例には、ArrayList を返す Vehicles という名前の単一のフィールドが含まれています。この例では、最初に XmlElementAttribute クラスの 2 つのインスタンスを Vehicles フィールドに適用しており、各インスタンスは、XmlSerializer が配列に挿入できるオブジェクトの型を指定しています。次に、2 つの XmlElementAttribute オブジェクトを作成し、Vehicles プロパティに適用される属性の動作をオーバーライドします。オーバーライドする側の 2 つのオブジェクトは、XmlAttributes の XmlElementAttributes コレクションに追加されます。最後に、この XmlAttributes を XmlAttributeOverrides に追加します。これにより、XmlSerializer が、Vehicles フィールドによって返される ArrayList に新しいオブジェクト型を挿入できるようになります。
Imports System Imports System.IO Imports System.Xml.Serialization Imports System.Collections Imports System.Xml Public Class Transportation ' Override these two XmlElementAttributes. <XmlElement(GetType(Car)), _ XmlElement(GetType(Plane))> _ Public Vehicles As ArrayList End Class Public Class Car Public Name As String End Class Public Class Plane Public Name As String End Class Public Class Truck Public Name As String End Class Public Class Train Public Name As String End Class Public Class Test Public Shared Sub Main() Dim t As New Test() t.SerializeObject("OverrideElement.xml") End Sub Public Function CreateOverrider() As XmlSerializer ' Create XmlAtrributes and XmlAttributeOverrides instances. Dim attrs As New XmlAttributes() Dim xOver As New XmlAttributeOverrides() ' Create an XmlElementAttributes object to override ' one of the attributes applied to the Vehicles property. Dim xElement1 As New XmlElementAttribute(GetType(Truck)) ' Add the XmlElementAttribute to the collection. attrs.XmlElements.Add(xElement1) ' Create a second XmlElementAttribute and ' add it to the collection. Dim xElement2 As New XmlElementAttribute(GetType(Train)) attrs.XmlElements.Add(xElement2) ' Add the XmlAttributes to the XmlAttributeOverrides, ' specifying the member to override. xOver.Add(GetType(Transportation), "Vehicles", attrs) ' Create the XmlSerializer, and return it. Dim xSer As New XmlSerializer(GetType(Transportation), xOver) Return xSer End Function Public Sub SerializeObject(ByVal filename As String) ' Create an XmlSerializer instance. Dim xSer As XmlSerializer = CreateOverrider() ' Create the object. Dim myTransportation As New Transportation() ' Create two new, overriding objects that can be ' inserted into the Vehicles array. myTransportation.Vehicles = New ArrayList() Dim myTruck As New Truck() myTruck.Name = "MyTruck" Dim myTrain As New Train() myTrain.Name = "MyTrain" myTransportation.Vehicles.Add(myTruck) myTransportation.Vehicles.Add(myTrain) Dim writer As New StreamWriter(filename) xSer.Serialize(writer, myTransportation) End Sub End Class
using System; using System.IO; using System.Xml.Serialization; using System.Collections; using System.Xml; public class Transportation { // Override these two XmlElementAttributes. [XmlElement(typeof(Car)), XmlElement(typeof(Plane))] public ArrayList Vehicles; } public class Car { public string Name; } public class Plane { public string Name; } public class Truck { public string Name; } public class Train { public string Name; } public class Test { public static void Main() { Test t = new Test(); t.SerializeObject("OverrideElement.xml"); } public XmlSerializer CreateOverrider() { // Create XmlAtrributes and XmlAttributeOverrides instances. XmlAttributes attrs = new XmlAttributes(); XmlAttributeOverrides xOver = new XmlAttributeOverrides(); /* Create an XmlElementAttributes object to override one of the attributes applied to the Vehicles property. */ XmlElementAttribute xElement1 = new XmlElementAttribute(typeof(Truck)); // Add the XmlElementAttribute to the collection. attrs.XmlElements.Add(xElement1); /* Create a second XmlElementAttribute and add it to the collection. */ XmlElementAttribute xElement2 = new XmlElementAttribute(typeof(Train)); attrs.XmlElements.Add(xElement2); /* Add the XmlAttributes to the XmlAttributeOverrides, specifying the member to override. */ xOver.Add(typeof(Transportation), "Vehicles", attrs); // Create the XmlSerializer, and return it. XmlSerializer xSer = new XmlSerializer (typeof(Transportation), xOver); return xSer; } public void SerializeObject(string filename) { // Create an XmlSerializer instance. XmlSerializer xSer = CreateOverrider(); // Create the object. Transportation myTransportation = new Transportation(); /* Create two new, overriding objects that can be inserted into the Vehicles array. */ myTransportation.Vehicles = new ArrayList(); Truck myTruck = new Truck(); myTruck.Name = "MyTruck"; Train myTrain = new Train(); myTrain.Name = "MyTrain"; myTransportation.Vehicles.Add(myTruck); myTransportation.Vehicles.Add(myTrain); TextWriter writer = new StreamWriter(filename); xSer.Serialize(writer, myTransportation); } }
#using <System.Xml.dll> #using <System.dll> using namespace System; using namespace System::IO; using namespace System::Xml::Serialization; using namespace System::Collections; using namespace System::Xml; public ref class Car { public: String^ Name; }; public ref class Plane { public: String^ Name; }; public ref class Truck { public: String^ Name; }; public ref class Train { public: String^ Name; }; public ref class Transportation { public: // Override these two XmlElementAttributes. [XmlElement(Car::typeid), XmlElement(Plane::typeid)] ArrayList^ Vehicles; }; XmlSerializer^ CreateOverrider() { // Create XmlAtrributes and XmlAttributeOverrides instances. XmlAttributes^ attrs = gcnew XmlAttributes; XmlAttributeOverrides^ xOver = gcnew XmlAttributeOverrides; /* Create an XmlElementAttributes object to override one of the attributes applied to the Vehicles property. */ XmlElementAttribute^ xElement1 = gcnew XmlElementAttribute( Truck::typeid ); // Add the XmlElementAttribute to the collection. attrs->XmlElements->Add( xElement1 ); /* Create a second XmlElementAttribute and add it to the collection. */ XmlElementAttribute^ xElement2 = gcnew XmlElementAttribute( Train::typeid ); attrs->XmlElements->Add( xElement2 ); /* Add the XmlAttributes to the XmlAttributeOverrides, specifying the member to override. */ xOver->Add( Transportation::typeid, "Vehicles", attrs ); // Create the XmlSerializer, and return it. XmlSerializer^ xSer = gcnew XmlSerializer( Transportation::typeid,xOver ); return xSer; } void SerializeObject( String^ filename ) { // Create an XmlSerializer instance. XmlSerializer^ xSer = CreateOverrider(); // Create the object. Transportation^ myTransportation = gcnew Transportation; /* Create two new, overriding objects that can be inserted into the Vehicles array. */ myTransportation->Vehicles = gcnew ArrayList; Truck^ myTruck = gcnew Truck; myTruck->Name = "MyTruck"; Train^ myTrain = gcnew Train; myTrain->Name = "MyTrain"; myTransportation->Vehicles->Add( myTruck ); myTransportation->Vehicles->Add( myTrain ); TextWriter^ writer = gcnew StreamWriter( filename ); xSer->Serialize( writer, myTransportation ); } int main() { SerializeObject( "OverrideElement.xml" ); }
import System.*; import System.IO.*; import System.Xml.Serialization.*; import System.Collections.*; import System.Xml.*; public class Transportation { // Override these two XmlElementAttributes. /** @attribute XmlElement(Car.class) @attribute XmlElement(Plane.class) */ public ArrayList vehicles; } //Transportation public class Car { public String name; } //Car public class Plane { public String name; } //Plane public class Truck { public String name; } //Truck public class Train { public String name; } //Train public class Test { public static void main(String[] args) { Test t = new Test(); t.SerializeObject("OverrideElement.xml"); } //main public XmlSerializer CreateOverrider() { // Create XmlAtrributes and XmlAttributeOverrides instances. XmlAttributes attrs = new XmlAttributes(); XmlAttributeOverrides xOver = new XmlAttributeOverrides(); /* Create an XmlElementAttributes object to override one of the attributes applied to the Vehicles property. */ XmlElementAttribute xElement1 = new XmlElementAttribute(Truck.class.ToType()); // Add the XmlElementAttribute to the collection. attrs.get_XmlElements().Add(xElement1); /* Create a second XmlElementAttribute and add it to the collection. */ XmlElementAttribute xElement2 = new XmlElementAttribute(Train.class.ToType()); attrs.get_XmlElements().Add(xElement2); /* Add the XmlAttributes to the XmlAttributeOverrides, specifying the member to override. */ xOver.Add(Transportation.class.ToType(), "vehicles", attrs); // Create the XmlSerializer, and return it. XmlSerializer xSer = new XmlSerializer(Transportation.class.ToType(), xOver); return xSer; } //CreateOverrider public void SerializeObject(String fileName) { // Create an XmlSerializer instance. XmlSerializer xSer = CreateOverrider(); // Create the object. Transportation myTransportation = new Transportation(); /* Create two new, overriding objects that can be inserted into the Vehicles array. */ myTransportation.vehicles = new ArrayList(); Truck myTruck = new Truck(); myTruck.name = "MyTruck"; Train myTrain = new Train(); myTrain.name = "MyTrain"; myTransportation.vehicles.Add(myTruck); myTransportation.vehicles.Add(myTrain); TextWriter writer = new StreamWriter(fileName); xSer.Serialize(writer, myTransportation); } //SerializeObject } //Test

System.Collections.CollectionBase
System.Xml.Serialization.XmlElementAttributes


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


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


XmlElementAttributes プロパティ

名前 | 説明 | |
---|---|---|
![]() | Capacity | CollectionBase に格納できる要素の数を取得または設定します。 ( CollectionBase から継承されます。) |
![]() | Count | CollectionBase インスタンスに格納されている要素の数を取得します。このプロパティはオーバーライドできません。 ( CollectionBase から継承されます。) |
![]() | Item | コレクションから XmlElementAttribute を取得または設定します。 |

名前 | 説明 | |
---|---|---|
![]() | InnerList | CollectionBase インスタンス内の要素のリストを格納する ArrayList を取得します。 ( CollectionBase から継承されます。) |
![]() | List | CollectionBase インスタンス内の要素のリストを格納する IList を取得します。 ( CollectionBase から継承されます。) |

XmlElementAttributes メソッド

名前 | 説明 | |
---|---|---|
![]() | Add | XmlElementAttribute をコレクションに追加します。 |
![]() | Clear | CollectionBase インスタンスからすべてのオブジェクトを削除します。このメソッドはオーバーライドできません。 ( CollectionBase から継承されます。) |
![]() | Contains | 指定したオブジェクトがコレクションに格納されているかどうかを指定する値を取得します。 |
![]() | CopyTo | XmlElementAttributes またはその一部を 1 次元配列にコピーします。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetEnumerator | CollectionBase インスタンスを反復処理する列挙子を返します。 ( CollectionBase から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | IndexOf | 指定した XmlElementAttribute のインデックスを取得します。 |
![]() | Insert | コレクションに XmlElementAttribute を挿入します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | Remove | 指定されたオブジェクトをコレクションから削除します。 |
![]() | RemoveAt | CollectionBase インスタンスの指定したインデックスにある要素を削除します。このメソッドはオーバーライドできません。 ( CollectionBase から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |
![]() | OnClear | CollectionBase インスタンスの内容を消去するときに、追加のカスタム プロセスを実行します。 ( CollectionBase から継承されます。) |
![]() | OnClearComplete | CollectionBase インスタンスの内容を消去した後に、追加のカスタム プロセスを実行します。 ( CollectionBase から継承されます。) |
![]() | OnInsert | CollectionBase インスタンスに新しい要素を挿入する前に、追加のカスタム プロセスを実行します。 ( CollectionBase から継承されます。) |
![]() | OnInsertComplete | CollectionBase インスタンスに新しい要素を挿入した後に、追加のカスタム プロセスを実行します。 ( CollectionBase から継承されます。) |
![]() | OnRemove | CollectionBase インスタンスから要素を削除するときに、追加のカスタム プロセスを実行します。 ( CollectionBase から継承されます。) |
![]() | OnRemoveComplete | CollectionBase インスタンスから要素を削除した後に、追加のカスタム プロセスを実行します。 ( CollectionBase から継承されます。) |
![]() | OnSet | CollectionBase インスタンスに値を設定する前に、追加のカスタム プロセスを実行します。 ( CollectionBase から継承されます。) |
![]() | OnSetComplete | CollectionBase インスタンスに値を設定した後に、追加のカスタム プロセスを実行します。 ( CollectionBase から継承されます。) |
![]() | OnValidate | 値を検証するときに、追加のカスタム プロセスを実行します。 ( CollectionBase から継承されます。) |

XmlElementAttributes メンバ
XmlSerializer がクラスをシリアル化する既定の方法をオーバーライドするために使用する、XmlElementAttribute オブジェクトのコレクションを表します。
XmlElementAttributes データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Capacity | CollectionBase に格納できる要素の数を取得または設定します。(CollectionBase から継承されます。) |
![]() | Count | CollectionBase インスタンスに格納されている要素の数を取得します。このプロパティはオーバーライドできません。(CollectionBase から継承されます。) |
![]() | Item | コレクションから XmlElementAttribute を取得または設定します。 |

名前 | 説明 | |
---|---|---|
![]() | InnerList | CollectionBase インスタンス内の要素のリストを格納する ArrayList を取得します。(CollectionBase から継承されます。) |
![]() | List | CollectionBase インスタンス内の要素のリストを格納する IList を取得します。(CollectionBase から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Add | XmlElementAttribute をコレクションに追加します。 |
![]() | Clear | CollectionBase インスタンスからすべてのオブジェクトを削除します。このメソッドはオーバーライドできません。 (CollectionBase から継承されます。) |
![]() | Contains | 指定したオブジェクトがコレクションに格納されているかどうかを指定する値を取得します。 |
![]() | CopyTo | XmlElementAttributes またはその一部を 1 次元配列にコピーします。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetEnumerator | CollectionBase インスタンスを反復処理する列挙子を返します。 (CollectionBase から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | IndexOf | 指定した XmlElementAttribute のインデックスを取得します。 |
![]() | Insert | コレクションに XmlElementAttribute を挿入します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | Remove | 指定されたオブジェクトをコレクションから削除します。 |
![]() | RemoveAt | CollectionBase インスタンスの指定したインデックスにある要素を削除します。このメソッドはオーバーライドできません。 (CollectionBase から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |
![]() | OnClear | CollectionBase インスタンスの内容を消去するときに、追加のカスタム プロセスを実行します。 (CollectionBase から継承されます。) |
![]() | OnClearComplete | CollectionBase インスタンスの内容を消去した後に、追加のカスタム プロセスを実行します。 (CollectionBase から継承されます。) |
![]() | OnInsert | CollectionBase インスタンスに新しい要素を挿入する前に、追加のカスタム プロセスを実行します。 (CollectionBase から継承されます。) |
![]() | OnInsertComplete | CollectionBase インスタンスに新しい要素を挿入した後に、追加のカスタム プロセスを実行します。 (CollectionBase から継承されます。) |
![]() | OnRemove | CollectionBase インスタンスから要素を削除するときに、追加のカスタム プロセスを実行します。 (CollectionBase から継承されます。) |
![]() | OnRemoveComplete | CollectionBase インスタンスから要素を削除した後に、追加のカスタム プロセスを実行します。 (CollectionBase から継承されます。) |
![]() | OnSet | CollectionBase インスタンスに値を設定する前に、追加のカスタム プロセスを実行します。 (CollectionBase から継承されます。) |
![]() | OnSetComplete | CollectionBase インスタンスに値を設定した後に、追加のカスタム プロセスを実行します。 (CollectionBase から継承されます。) |
![]() | OnValidate | 値を検証するときに、追加のカスタム プロセスを実行します。 (CollectionBase から継承されます。) |

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

- XmlElementAttributesのページへのリンク