//On instancie un nouveau XmlDocument
XmlDocument docxml=new XmlDocument();
//on crée le premier noeud avec les spécifications du document XML
XmlDeclaration declaration=docxml.CreateXmlDeclaration("1.0","utf-8","");
//On ajoute la déclaration au document
docxml.AppendChild(declaration);
//On crée le noeud racine du document
XmlNode racine=docxml.CreateNode(System.Xml.XmlNodeType.Element,"Agenda","");
//On ajoute ce noeud au document
docxml.AppendChild(racine);
//On crée un nouveau noeud pour la première personne
XmlNode personne1 = docxml.CreateElement("Personne");
//On ajoute un attribut "nom" à ce noeud personne
XmlAttribute nom_personne1=docxml.CreateAttribute("Nom");
nom_personne1.Value="Mickael";
personne1.Attributes.Append(nom_personne1);
//On ajoute les différentes propriétés à personne
//Age
XmlNode propriete1=docxml.CreateElement("Age");
propriete1.InnerText="20";
personne1.AppendChild(propriete1);
//Ville
XmlNode propriete2=docxml.CreateElement("Ville");
propriete2.InnerText="Saint Benoit";
personne1.AppendChild(propriete2);
//On ajoute la personne1 au document
racine.AppendChild(personne1);
docxml.Save("agenda.xml");