Mega Code Archive

 
Categories / C# / XML
 

XmlReader MoveToAttribute (Int32) moves to the attribute with the specified index

using System; using System.IO; using System.Xml; public class Sample {     public static void Main()     {         XmlReader reader = XmlReader.Create("book.xml");         reader.ReadToDescendant("book");         if (reader.HasAttributes)         {             Console.WriteLine("Attributes of <" + reader.Name + ">");             for (int i = 0; i < reader.AttributeCount; i++)             {                 reader.MoveToAttribute(i);                 Console.Write(" {0}={1}", reader.Name, reader.Value);             }             reader.MoveToElement(); // Moves the reader back to the element node.         }     } }