XmlNodeReader.MoveToAttribute メソッド

定義

指定された属性に移動します。

オーバーロード

MoveToAttribute(Int32)

指定したインデックスを持つ属性に移動します。

MoveToAttribute(String)

指定した名前を持つ属性へ移動します。

MoveToAttribute(String, String)

指定したローカル名および名前空間 URI の属性に移動します。

MoveToAttribute(Int32)

指定したインデックスを持つ属性に移動します。

public:
 override void MoveToAttribute(int attributeIndex);
public override void MoveToAttribute (int attributeIndex);
override this.MoveToAttribute : int -> unit
Public Overrides Sub MoveToAttribute (attributeIndex As Integer)

パラメーター

attributeIndex
Int32

属性のインデックス。

例外

i パラメーターが 0 未満か、AttributeCount 以上です。

次の例では、ルート ノード上のすべての属性を読み取ります。

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlNodeReader^ reader = nullptr;
   try
   {
      
      //Create and load the XML document.
      XmlDocument^ doc = gcnew XmlDocument;
      doc->LoadXml( "<book genre='novel' ISBN='1-861003-78' publicationdate='1987'> "
      "</book>" );
      
      //Load the XmlNodeReader 
      reader = gcnew XmlNodeReader( doc );
      
      //Read the attributes on the root element.
      reader->MoveToContent();
      if ( reader->HasAttributes )
      {
         for ( int i = 0; i < reader->AttributeCount; i++ )
         {
            reader->MoveToAttribute( i );
            Console::WriteLine( "{0} = {1}", reader->Name, reader->Value );

         }
         reader->MoveToElement();
      }
   }
   finally
   {
      if ( reader != nullptr )
            reader->Close();
   }

}
using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {
    XmlNodeReader reader = null;

    try
    {
       //Create and load the XML document.
       XmlDocument doc = new XmlDocument();
       doc.LoadXml("<book genre='novel' ISBN='1-861003-78' publicationdate='1987'> " +
                   "</book>");

       //Load the XmlNodeReader
       reader = new XmlNodeReader(doc);

       //Read the attributes on the root element.
       reader.MoveToContent();
       if (reader.HasAttributes){
         for (int i=0; i<reader.AttributeCount; i++){
            reader.MoveToAttribute(i);
            Console.WriteLine("{0} = {1}", reader.Name, reader.Value);
         }
         //Return the reader to the book element.
         reader.MoveToElement();
       }
     }

     finally
     {
        if (reader != null)
          reader.Close();
      }
  }
} // End class
Option Strict
Option Explicit

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        Dim reader As XmlNodeReader = Nothing
        Try
            'Create and load the XML document.
            Dim doc As New XmlDocument()
            doc.LoadXml("<book genre='novel' ISBN='1-861003-78' publicationdate='1987'> " & _
                       "</book>")
            
            'Load the XmlNodeReader 
            reader = New XmlNodeReader(doc)
            
            'Read the attributes on the root element.
            reader.MoveToContent()
            If reader.HasAttributes Then
                Dim i As Integer
                For i = 0 To reader.AttributeCount - 1
                    reader.MoveToAttribute(i)
                    Console.WriteLine("{0} = {1}", reader.Name, reader.Value)
                Next i
                'Return the reader to the book element.
                reader.MoveToElement()
            End If
        
        Finally
            If Not (reader Is Nothing) Then
                reader.Close()
            End If
        End Try
    End Sub
End Class

注釈

Note

.NET Framework 2.0 では、 クラスと Create メソッドを使用してインスタンスをXmlReaderSettings作成XmlReaderすることをお勧めします。 これにより、.NET Frameworkで導入されたすべての新機能を最大限に活用できます。 詳細については、リファレンス ページの「解説」セクションを XmlReader 参照してください。

適用対象

MoveToAttribute(String)

指定した名前を持つ属性へ移動します。

public:
 override bool MoveToAttribute(System::String ^ name);
public override bool MoveToAttribute (string name);
override this.MoveToAttribute : string -> bool
Public Overrides Function MoveToAttribute (name As String) As Boolean

パラメーター

name
String

属性の限定名。

戻り値

属性が見つかった場合は true。それ以外の場合は falsefalse の場合、リーダーの位置は変更されません。

注釈

Note

.NET Framework 2.0 では、 クラスと Create メソッドを使用してインスタンスをXmlReaderSettings作成XmlReaderすることをお勧めします。 これにより、.NET Frameworkで導入されたすべての新機能を最大限に活用できます。 詳細については、リファレンス ページの「解説」セクションを XmlReader 参照してください。

このメソッドを呼び出した後、NameNamespaceURIおよび Prefix プロパティには、その属性のプロパティが反映されます。

適用対象

MoveToAttribute(String, String)

指定したローカル名および名前空間 URI の属性に移動します。

public:
 override bool MoveToAttribute(System::String ^ name, System::String ^ namespaceURI);
public override bool MoveToAttribute (string name, string? namespaceURI);
public override bool MoveToAttribute (string name, string namespaceURI);
override this.MoveToAttribute : string * string -> bool
Public Overrides Function MoveToAttribute (name As String, namespaceURI As String) As Boolean

パラメーター

name
String

属性のローカル名。

namespaceURI
String

属性の名前空間 URI。

戻り値

属性が見つかった場合は true。それ以外の場合は falsefalse の場合、リーダーの位置は変更されません。

注釈

Note

.NET Framework 2.0 では、 クラスと Create メソッドを使用してインスタンスをXmlReaderSettings作成XmlReaderすることをお勧めします。 これにより、.NET Frameworkで導入されたすべての新機能を最大限に活用できます。 詳細については、リファレンス ページの「解説」セクションを XmlReader 参照してください。

このメソッドを呼び出した後、NameNamespaceURIおよび Prefix プロパティには、その属性のプロパティが反映されます。

適用対象