XmlValidatingReader.MoveToNextAttribute 方法

定义

移动到下一个属性。

public:
 override bool MoveToNextAttribute();
public override bool MoveToNextAttribute ();
override this.MoveToNextAttribute : unit -> bool
Public Overrides Function MoveToNextAttribute () 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 引用页的“备注”部分。

如果当前节点是元素节点,则此方法等效 MoveToFirstAttribute于 。 如果 MoveToNextAttribute 返回 true,读取器将移动到下一个属性;否则,读取器的位置不会更改。

适用于

另请参阅