using System;
using System.Xml;
public class Sample
{
public static void Main()
{
using (XmlReader reader = XmlReader.Create("books.xml"))
{
reader.MoveToContent();
reader.ReadToDescendant("book");
reader.Skip();
do
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
Console.Write("<{0}", reader.Name);
while (reader.MoveToNextAttribute())
{
Console.Write(" {0}='{1}'", reader.Name, reader.Value);
}
Console.Write(">");
break;
case XmlNodeType.Text:
Console.Write(reader.Value);
break;
case XmlNodeType.EndElement:
Console.Write("{0}>", reader.Name);
break;
}
} while (reader.Read());
}
}
}