Mega Code Archive

 
Categories / C# / XML
 

XmlReader ReadInnerXml reads all the content, including markup, as a string

using System; using System.Xml; public class Sample {     public static void 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());         }     } }