XmlReader.ReadInnerXml reads all the content, including markup, as a string.
using System;
using System.Xml;
publicclass Sample
{
publicstaticvoid Main()
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
using (XmlReader reader = XmlReader.Create("books.xml"))
{
// Moves the reader to the root element.
reader.MoveToContent();
// Moves to book node.
reader.Read();
Console.WriteLine("Read the first book using ReadInnerXml...");
Console.WriteLine(reader.ReadInnerXml());
Console.WriteLine("Read the second book using ReadOuterXml...");
Console.WriteLine(reader.ReadOuterXml());
}
}
}