XmlTextReader.MoveToNextAttribute 方法

定義

移至下一個屬性。

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

傳回

如果有下一個屬性,則為 true,如果沒有其他屬性,則為 false

範例

下列範例會顯示目前節點上的所有屬性。

public:
   void DisplayAttributes( XmlReader^ reader )
   {
      if ( reader->HasAttributes )
      {
         Console::WriteLine( "Attributes of <{0}>", reader->Name );
         while ( reader->MoveToNextAttribute() )
         {
            Console::WriteLine( " {0}={1}", reader->Name, reader->Value );
         }
      }
   }
public void DisplayAttributes(XmlReader reader)
{
    if (reader.HasAttributes)
    {
        Console.WriteLine("Attributes of <" + reader.Name + ">");
        while (reader.MoveToNextAttribute())
        {
            Console.WriteLine(" {0}={1}", reader.Name, reader.Value);
        }
    }
}
Public Sub DisplayAttributes(reader As XmlReader)
    If reader.HasAttributes Then
        Console.WriteLine("Attributes of <" & reader.Name & ">")
        While reader.MoveToNextAttribute()
            Console.WriteLine(" {0}={1}", reader.Name, reader.Value)
        End While
    End If
End Sub

備註

注意

從 .NET Framework 2.0 開始,建議您使用 XmlReader.Create 方法來建立 XmlReader 實例,以利用新功能。

如果目前的節點是專案節點,這個方法就相當於 MoveToFirstAttribute 。 如果傳 MoveToNextAttributetrue ,則讀取器會移至下一個屬性,否則讀取器的位置不會變更。

適用於

另請參閱