using System.Collections.ObjectModel;
using System.Xml.Serialization;
public static void Main()
var result = Serializer.Deserialize();
Console.WriteLine("text: {0}", result.StringProperty);
Console.WriteLine("number: {0}", result.IntegerProperty);
Console.WriteLine("enum: {0}", result.EnumProperty);
Console.WriteLine("child[0].Value: {0}", result.CollectionProperty[0].Value);
Console.WriteLine("other@[0]: {0}", result.OtherAttributes[0].InnerText);
Console.WriteLine("other*[0]: {0}", result.OtherElements[0].InnerText);
Console.WriteLine("other*[0]: {0}", result.Value);
public static class Serializer
public static RootClass Deserialize()
var type = typeof (RootClass);
var serializer = new XmlSerializer(type);
<root textAttribute='tex1t' numberAttribute='1' enumAttribute='item1' attributeToIgnore1='ignored1' attributeToIgnore2='ignored2'>
<childToIgnore>ignored3</childToIgnore>
<DateTime>Exclusive <b> Hangzhou Zhongshan International Hotel Superior Room </b>1 Night + Free breakfast 2 parts + Free wifi+ more benefits! Hotel is located in the bustling Lakeside shopping district, adjacent to the subway line Line 1 long Xiang Station D exit, walk to the West Lake just 10 minutes, surrounded by shops, traffic is very convenient!</DateTime>
using (var stringReader = new StringReader(xmlString))
return serializer.Deserialize(stringReader) as RootClass;
[XmlAttribute("textAttribute")]
public string StringProperty;
[XmlAttribute("numberAttribute")]
public int IntegerProperty;
[XmlAttribute("enumAttribute")]
public Enumeration EnumProperty;
public XmlAttribute[] OtherAttributes;
public Collection<ChildClass> CollectionProperty;
[XmlElement("DateTime", typeof(string))]
public object Value { get; set; }
public XmlElement[] OtherElements;