//Create a new xmlDataDocument
XmlDataDocument myDoc = new XmlDataDocument();
//The familie
XmlElement Familie = myDoc.CreateElement(“Familie”);
//The elements wrapper
XmlElement wrapper = myDoc.CreateElement(“xml”);
//Create attributes
XmlAttribute version = myDoc.CreateAttribute(“version”);
XmlAttribute encoding = myDoc.CreateAttribute(“encoding”);
//Add values to attributes
version.Value = “1.0”;
encoding.Value = “utf-8”;
//Append attributes to their correspondent element
wrapper.Attributes.Append(version);
wrapper.Attributes.Append(encoding);
//The Father
XmlElement Father = myDoc.CreateElement(“Father”);
//Create attributes
XmlAttribute FatherName = myDoc.CreateAttribute(“Name”);
XmlAttribute FatherAge = myDoc.CreateAttribute(“Age”);
//Add values to attributes
FatherName.Value = “My father”;
FatherAge.Value = “65”;
//Append attributes to their correspondent element
Father.Attributes.Append(FatherName);
Father.Attributes.Append(FatherAge);
//Add the element to the Familie node
Familie.AppendChild(Father);
//The mother
XmlElement Mother = myDoc.CreateElement(“Mother”);
//Create attributes
XmlAttribute MotherName = myDoc.CreateAttribute(“Name”);
XmlAttribute MotherAge = myDoc.CreateAttribute(“Age”);
//Add values to attributes
MotherName.Value = “My mother”;
MotherAge.Value = “60”;
//Append attributes to their correspondent element
Mother.Attributes.Append(MotherName);
Mother.Attributes.Append(MotherAge);
//Add the element to the Familie node
Familie.AppendChild(Mother);
//The sister
XmlElement Sister = myDoc.CreateElement(“Sister”);
//Create attributes
XmlAttribute SisterName = myDoc.CreateAttribute(“Name”);
XmlAttribute SisterAge = myDoc.CreateAttribute(“Age”);
//Add values to attributes
SisterName.Value = “My sister”;
SisterAge.Value = “20”;
//Append attributes to their correspondent element
Sister.Attributes.Append(SisterName);
Sister.Attributes.Append(SisterAge);
//Add the element to the Familie node
Familie.AppendChild(Sister);
//The brother
XmlElement Brother = myDoc.CreateElement(“Brother”);
//Create attributes
XmlAttribute BrotherName = myDoc.CreateAttribute(“Name”);
XmlAttribute BrotherAge = myDoc.CreateAttribute(“Age”);
//Add values to attributes
BrotherName.Value = “My brother”;
BrotherAge.Value = “21”;
//Append attributes to their correspondent element
Brother.Attributes.Append(BrotherName);
Brother.Attributes.Append(BrotherAge);
//Add the element to the Familie node
Familie.AppendChild(Brother);
//wrapp all elements nodes in wrapper node
wrapper.AppendChild(Familie);
//Add the entire node in to the docuement
myDoc.AppendChild(wrapper);
//Save the xml document
myDoc.Save(@”C:\myFamilie.xml”);
//Give a signal that all gonna be all right
Console.WriteLine(“Document is generated successfully!!”);
Console.Read();