Mega Code Archive

 
Categories / C# / XML
 

XmlReader ReadElementString reads a text-only element

using System; using System.Xml; public class Sample {     public static void Main()     {         XmlTextReader reader = null;         try         {             reader = new XmlTextReader("book.xml");             reader.WhitespaceHandling = WhitespaceHandling.None;             reader.MoveToContent();             Console.WriteLine("Content of the title element: {0}", reader.ReadElementString());             Console.WriteLine("Content of the price element: {0}", reader.ReadElementString()); ;         }         finally         {             if (reader != null)                 reader.Close();         }     } } //<book genre='novel' ISBN='1-11111-11' misc='XML'> //  <title>C#</title> //  <price>4.95</price> //</book>