using System.Xml; XmlTextReader reader = new XmlTextReader("example.xml"); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "title") { string title = reader.ReadElementString(); Console.WriteLine(title); } }
using System.Xml; XmlTextReader reader = new XmlTextReader("example.xml"); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { string content = reader.ReadElementString(); Console.WriteLine(content); } }This example reads an XML file named "example.xml" and reads the text content of all element nodes in the file using the ReadElementString method. The text content is then printed to the console. The XmlTextReader class is part of the System.Xml namespace in C#.