Recently I had a requirement where I had to create an XML file without any definitive structure but from a Class file. I had to write a tag for each class and a child property for each property.

Then instead of going for a primitive method of using the XML Document class, I went for LINQ to XML. The XElement makes life very easy when writing an XML. I just had to write 2 recursive methods to write the entire XML file.

This article helped a lot.