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());
}
}
}
And if it was omitted.
Notice the location of the second person we added tomek.