// Create new XmlTextReader object XmlTextReader reader = new XmlTextReader("myxmlfile.xml"); // Read until theelement is found while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "content") { // Read the content as a string string content = reader.ReadContentAsString(); Console.WriteLine("Content: " + content); } }
// Create new XmlTextReader object XmlTextReader reader = new XmlTextReader("myxmlfile.xml"); // Read the entire file as a string string xml = reader.ReadContentAsString(); Console.WriteLine("XML content: " + xml);This example reads the entire XML file as a string using the ReadContentAsString method and prints it to the console. The package library for System.Xml.XmlTextReader is System.Xml.ReaderWriter.