XmlValidatingReader.MoveToFirstAttribute 方法

定义

移动到第一个属性。

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

返回

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 引用页的“备注”部分。

适用于

另请参阅