using System.Collections.Generic;
using System.Xml.Serialization;
public PropertyList PropertyList { get; set; }
public class PropertyList
public List<Datum> Datum { get; set; }
public string qualifier { get; set; }
public string Value { get; set; }
var xml = @"<ListOfStuff>
<Datum qualifier=""areaType"">square</Datum>
<Datum qualifier=""color"">red</Datum>
public static void Main()
var test = GetXml().LoadFromXML<ListOfStuff>();
var xml2 = test.GetXml(true);
Console.WriteLine("Re-serialized XML: ");
if (!XNode.DeepEquals(XElement.Parse(xml2), XElement.Parse(GetXml())))
Console.WriteLine("Failed");
throw new InvalidOperationException("!XNode.DeepEquals(XElement.Parse(xml2), XElement.Parse(GetXml()))");
Console.WriteLine("Original and re-serialized XML are equivalent.");
public static class XmlSerializationHelper
public static T LoadFromXML<T>(this string xmlString)
using (StringReader reader = new StringReader(xmlString))
return (T)new XmlSerializer(typeof(T)).Deserialize(reader);
public static string GetXml<T>(this T obj, bool omitStandardNamespaces = false)
XmlSerializerNamespaces ns = null;
if (omitStandardNamespaces)
ns = new XmlSerializerNamespaces();
using (var textWriter = new StringWriter())
var settings = new XmlWriterSettings() { Indent = true, IndentChars = " " };
using (var xmlWriter = XmlWriter.Create(textWriter, settings))
new XmlSerializer(obj.GetType()).Serialize(xmlWriter, obj, ns);
return textWriter.ToString();