XmlNodeReader.MoveToFirstAttribute メソッド

定義

最初の属性に移動します。

public:
 override bool MoveToFirstAttribute();
public override bool MoveToFirstAttribute();
override this.MoveToFirstAttribute : unit -> bool
Public Overrides Function MoveToFirstAttribute () As Boolean

返品

true 属性が存在する場合 (リーダーは最初の属性に移動します)。それ以外の場合は、 false (リーダーの位置は変更されません)。

次の例では、ルート ノードの最初の属性の値を取得します。

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 genre attribute.
       reader.MoveToContent();
       reader.MoveToFirstAttribute();
       string genre=reader.Value;
       Console.WriteLine("The genre value: " + genre);
     }
     finally
     {
        if (reader != null)
          reader.Close();
      }
  }
} // End class
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 genre attribute.
            reader.MoveToContent()
            reader.MoveToFirstAttribute()
            Dim genre As String = reader.Value
            Console.WriteLine("The genre value: " & genre)
        
        Finally
            If Not (reader Is Nothing) Then
                reader.Close()
            End If
        End Try
    End Sub
End Class

注釈

Note

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

適用対象