Mega Code Archive

 
Categories / C# / XML
 

XmlReader ReadElementContentAs(Type, IXmlNamespaceResolver) reads the element content as the requested type

using System; using System.IO; using System.Xml; public class Sample  {   public static void Main(){       using (XmlReader reader = XmlReader.Create("dataFile.xml")) {            reader.ReadToFollowing("date");            DateTime date = (DateTime) reader.ReadElementContentAs(typeof(System.DateTime), null);            Console.WriteLine(date.ToLongDateString());         }   } }