using System;
using System.IO;
using System.Xml;
class Program
{
static void Main(string[] args)
{
using (var sw = new StringWriter())
{
using (var writer = XmlWriter.Create(sw,
new XmlWriterSettings() { Indent = true }))
{
writer.WriteStartDocument();
writer.WriteStartElement("People");
writer.WriteStartElement("Person");
writer.WriteAttributeString("FirstName", "Pawel");
writer.WriteAttributeString("LastName", "Chooch");
writer.WriteStartElement("ContactDetails");
writer.WriteElementString("EmailAddress", "fake@yahoo.com");
writer.WriteEndElement(); //contactDetails
writer.WriteEndElement(); //Person
writer.WriteStartElement("Person");
writer.WriteAttributeString("FirstName", "Tomek");
writer.WriteAttributeString("LastName", "Chooch");
writer.Flush();
}
Console.WriteLine(sw.ToString());
}
}
}
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuawKUGAtweWiEIq7rA3OiKMj_kuziSD2k2Us7B10H5VIQFoqLOoDwx2cQcAzwImjv0u7jx5tyji0IlNvxDexiYSHk_n1ShbKkSdbvqIHyH5yHZX3cMHHrrdbDZllnBBp1HWll0cU9-Cw/s1600/a1.png)
And if it was omitted.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrGleR600mLkKLBBbIquKrfsBaGbAQYs1GJlpzJI8VUJHWW8l-WXzf7KvZBlb6dAZUhNM7B5K9qoGF2ZI7KsoKLypaVyncVh5DtB9ejN8pN4r2tH6GhYjl40bRA32vMnxUfdMt8zH7Mf4/s1600/a2.png)
Notice the location of the second person we added tomek.