次の方法で共有


XmlAttributeCollection.CopyTo メソッド

このコレクション内のすべての XmlAttribute オブジェクトを、指定した配列にコピーします。

Public Sub CopyTo( _
   ByVal array() As XmlAttribute, _   ByVal index As Integer _)
[C#]
public void CopyTo(XmlAttribute[] array,intindex);
[C++]
public: void CopyTo(XmlAttribute* array[],intindex);
[JScript]
public function CopyTo(
   array : XmlAttribute[],index : int);

パラメータ

  • array
    このコレクションからコピーされたオブジェクトのコピー先の配列。
  • index
    array 内のコピー開始位置を示すインデックス。

解説

このメソッドは、ドキュメント オブジェクト モデル (DOM: Document Object Model) に対する Microsoft 拡張機能です。

使用例

[Visual Basic, C#, C++] CopyTo を使用して、コレクション内のすべての属性を配列にコピーする例を次に示します。

 
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>")      

    'Create an attribute collection.  
    Dim attrColl as XmlAttributeCollection = doc.DocumentElement.Attributes

    'Declare the array.
    Dim array(1) as XmlAttribute
    Dim index as integer=0

    'Copy all the attributes into the array.
    attrColl.CopyTo(array, index)

    Console.WriteLine("Display all the attributes in the array...")
    Dim attr as XmlAttribute
    for each attr in array
      Console.WriteLine("{0} = {1}",attr.Name,attr.Value)
    next
        
  end sub
end class

[C#] 
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>");      

    //Create an attribute collection.
    XmlAttributeCollection attrColl = doc.DocumentElement.Attributes;

    //Declare the array.
    XmlAttribute[] array = new XmlAttribute[2];
    int index=0;

    //Copy all the attributes into the array.
    attrColl.CopyTo(array, index);

    Console.WriteLine("Display all the attributes in the array..");
    foreach (XmlAttribute attr in array){
      Console.WriteLine("{0} = {1}",attr.Name,attr.Value);
    } 
  
  }
}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
{
    XmlDocument* doc = new XmlDocument();
    doc->LoadXml(S"<book genre='novel' ISBN='1-861001-57-5'><title>Pride And Prejudice</title></book>");      

    //Create an attribute collection.
    XmlAttributeCollection* attrColl = doc->DocumentElement->Attributes;

    //Declare the array.
    XmlAttribute* array[] = new XmlAttribute*[2];
    int index=0;

    //Copy all the attributes into the array.
    attrColl->CopyTo(array, index);

    Console::WriteLine(S"Display all the attributes in the array..");
    System::Collections::IEnumerator* myEnum = array->GetEnumerator();
    while (myEnum->MoveNext())
    {
        XmlAttribute* attr = __try_cast<XmlAttribute*>(myEnum->Current);
        Console::WriteLine(S"{0} = {1}",attr->Name,attr->Value);
    } 
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

XmlAttributeCollection クラス | XmlAttributeCollection メンバ | System.Xml 名前空間