Mega Code Archive

 
Categories / C# / XML
 

XmlReader ReadContentAs reads the content as an object of the type specified

using System; using System.IO; using System.Xml; public class Sample {     public static void Main()     {         using (XmlReader reader = XmlReader.Create("book.xml"))         {             reader.ReadToDescendant("item");             reader.MoveToAttribute("colors");             string[] colors = (string[])reader.ReadContentAs(typeof(string[]), null);             foreach (string color in colors)             {                 Console.WriteLine("Colors: {0}", color);             }         }     } }