Export (0) Print
Expand All

XmlValidatingReader.MoveToFirstAttribute Method

Moves to the first attribute.

[Visual Basic]
Overrides Public Function MoveToFirstAttribute() As Boolean
[C#]
public override bool MoveToFirstAttribute();
[C++]
public: bool MoveToFirstAttribute();
[JScript]
public override function MoveToFirstAttribute() : Boolean;

Return Value

true if an attribute exists (the reader moves to the first attribute); otherwise, false (the position of the reader does not change).

Example

[Visual Basic, C#, C++] The following example reads an XML fragment.

[Visual Basic] 
Imports System
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 

[C#] 
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

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
{

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

    //Read the genre attribute.
    reader->MoveToContent();
    reader->MoveToFirstAttribute();
    String* genre=reader->Value;
    Console::WriteLine(S"The genre value: {0}", genre);

    //Close the reader.
    reader->Close();

} 

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

XmlValidatingReader Class | XmlValidatingReader Members | System.Xml Namespace

Show:
© 2014 Microsoft