Export (0) Print
Expand All

XmlNodeReader.MoveToNextAttribute Method

Moves to the next attribute.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public override bool MoveToNextAttribute()

Return Value

Type: System.Boolean
true if there is a next attribute; false if there are no more attributes.

NoteNote

In the .NET Framework 2.0, the recommended practice is to create XmlReader instances using the XmlReaderSettings class and the Create method. This allows you to take full advantage of all the new features introduced in the .NET Framework. For more information, see the Remarks section in the XmlReader reference page.

If the current node is not an attribute node, this method is equivalent to MoveToFirstAttribute. If MoveToNextAttribute returns true, the reader moves to the next attribute; otherwise, the position of the reader does not change.

The following example reads a book.

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

public class Sample 
{
  public static void Main()
  {
    XmlNodeReader reader = null;

    try
    {
       //Create and load the XML document.
       XmlDocument doc = new XmlDocument();
       doc.LoadXml("<book genre='novel' ISBN='1-861003-78'> " +
                   "<title>Pride And Prejudice</title>" +
                   "<price>19.95</price>" +
                   "</book>"); 

       //Load the XmlNodeReader 
       reader = new XmlNodeReader(doc);

       //Read the attributes on the book element.
       reader.MoveToContent();
       while (reader.MoveToNextAttribute())
       {
         Console.WriteLine("{0} = {1}", reader.Name, reader.Value);
       }

       //Move the reader to the title element.
       reader.Read();

       //Read the title and price elements.
       Console.WriteLine(reader.ReadElementString());
       Console.WriteLine(reader.ReadElementString());

     } 

     finally 
     {
        if (reader != null)
          reader.Close();
      }
  }
} // End class

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0
Show:
© 2015 Microsoft