共用方式為


XmlValidatingReader.MoveToFirstAttribute 方法

定義

移至第一個屬性。

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

傳回

如果屬性存在 (讀取器移至第一個屬性),則為 true,否則為 false (不會變更讀取器的位置)。

範例

下列範例會讀取 XML 片段。

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   //Create the validating reader.
   XmlTextReader^ txtreader = gcnew XmlTextReader( "attrs.xml" );
   XmlValidatingReader^ reader = gcnew XmlValidatingReader( txtreader );
   
   //Read the genre attribute.
   reader->MoveToContent();
   reader->MoveToFirstAttribute();
   String^ genre = reader->Value;
   Console::WriteLine( "The genre value: {0}", genre );
   
   //Close the reader.
   reader->Close();
}

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

public class Sample
{
  public static void Main()
  {

    //Create the validating reader.
    XmlTextReader txtreader = new XmlTextReader("attrs.xml");
    XmlValidatingReader reader = new XmlValidatingReader(txtreader);

    //Read the genre attribute.
    reader.MoveToContent();
    reader.MoveToFirstAttribute();
    string genre=reader.Value;
    Console.WriteLine("The genre value: " + genre);

    //Close the reader.
    reader.Close();
  }
} // End class
Imports System.IO
Imports System.Xml

public class Sample 

  public shared sub Main()

    'Create the validating reader.
    Dim txtreader as XmlTextReader = new XmlTextReader("attrs.xml")
    Dim reader as XmlValidatingReader = new XmlValidatingReader(txtreader)

    'Read the genre attribute.
    reader.MoveToContent()
    reader.MoveToFirstAttribute()
    Dim genre As String = reader.Value
    Console.WriteLine("The genre value: " & genre)

    'Close the reader.
    reader.Close()

  End sub
End class 

備註

注意

類別 XmlValidatingReader 在 .NET Framework 2.0 中已過時。 您可以使用 類別和 Create 方法建立驗證 XmlReader 實例 XmlReaderSettings 。 如需詳細資訊,請參閱 XmlReader 參考頁面的<備註>一節。

適用於

另請參閱