XmlTextReader reader = new XmlTextReader("books.xml"); reader.WhitespaceHandling = WhitespaceHandling.None; while (reader.ReadToFollowing("book")) { Console.WriteLine("Found Book Element"); }
XmlTextReader reader = new XmlTextReader("orders.xml"); while (reader.ReadToFollowing("order")) { int orderId = int.Parse(reader.GetAttribute("id")); double total = double.Parse(reader.GetAttribute("total")); Console.WriteLine("Order ID: {0}, Total: {1:C}", orderId, total); }This code opens the "orders.xml" file, and reads through each order element in the file using the ReadToFollowing("order") method. It then extracts the order ID and total attributes from each order element using the GetAttribute() method, which are then used to output the order details to the console. Overall, the System.Xml.XmlTextReader class provides a simple way to read and parse XML data in a C# application.