using System.Collections.Generic;
using ExtendedXmlSerializer;
using ExtendedXmlSerializer.Configuration;
using ExtendedXmlSerializer.ExtensionModel;
public static void Main()
IExtendedXmlSerializer_Serialize_ProducesCustomXml();
public static void IExtendedXmlSerializer_Serialize_ProducesCustomXml()
var people = new List<Person> { new Person("Princess Eugenie"), new Person("Princess Beatrice") };
var aunts = new List<Person> { new Person("Princess Anne") };
var uncles = new List<Person> { new Person("Price Charles"), new Person("Price Andrew"), new Person("Price Edward") };
people[0].Uncles = uncles;
people[1].Aunts = aunts.ToList();
people[1].Uncles = uncles.ToList();
IExtendedXmlSerializer serializer = new ConfigurationContainer()
.UseOptimizedNamespaces()
.EnableImplicitTyping(typeof(Person))
result = serializer.Serialize(people);
Console.WriteLine(result);
if (result != @"<?xml version=""1.0"" encoding=""utf-8""?><List><XmlRefTests-Person><Name>Princess Eugenie</Name><Uncles><XmlRefTests-Person id=""2""><Name>Price Charles</Name></XmlRefTests-Person><XmlRefTests-Person id=""3""><Name>Price Andrew</Name></XmlRefTests-Person><XmlRefTests-Person id=""4""><Name>Price Edward</Name></XmlRefTests-Person></Uncles><Aunts><XmlRefTests-Person id=""1""><Name>Princess Anne</Name></XmlRefTests-Person></Aunts></XmlRefTests-Person><XmlRefTests-Person><Name>Princess Beatrice</Name><Uncles><XmlRefTests-Person ref=""2"" /><XmlRefTests-Person ref=""3"" /><XmlRefTests-Person ref=""4"" /></Uncles><Aunts><XmlRefTests-Person ref=""1"" /></Aunts></XmlRefTests-Person></List>")
throw new Exception("Xml mismatch.");
public Person(string name)
public string Name { get; set; }
public List<Person> Uncles { get; set; }
public List<Person> Aunts { get; set; }