using System; using System.Xml; public class GenererDocXML { private static void Main() { XmlDocument doc = new XmlDocument(); XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null); doc.AppendChild(docNode); XmlNode nouedProg = doc.CreateElement("Programmations"); doc.AppendChild(nouedProg); XmlNode noeudLang = doc.CreateElement("Language"); XmlAttribute attributLang = doc.CreateAttribute("ID"); attributLang.Value = "01"; noeudLang.Attributes.Append(attributLang); nouedProg.AppendChild(noeudLang); // Créer les éléments, les attributs et les valeurs XmlNode noeudNom = doc.CreateElement("Nom"); noeudNom.AppendChild(doc.CreateTextNode("C#")); noeudLang.AppendChild(noeudNom); XmlNode priceNode = doc.CreateElement("Type"); priceNode.AppendChild(doc.CreateTextNode("Orienté Objet")); noeudLang.AppendChild(priceNode); noeudLang = doc.CreateElement("Language"); attributLang = doc.CreateAttribute("ID"); attributLang.Value = "02"; noeudLang.Attributes.Append(attributLang); nouedProg.AppendChild(noeudLang); noeudNom = doc.CreateElement("Nom"); noeudNom.AppendChild(doc.CreateTextNode("Java")); noeudLang.AppendChild(noeudNom); priceNode = doc.CreateElement("Type"); priceNode.AppendChild(doc.CreateTextNode("Orienté Objet")); noeudLang.AppendChild(priceNode); noeudLang = doc.CreateElement("Language"); attributLang = doc.CreateAttribute("ID"); attributLang.Value = "03"; noeudLang.Attributes.Append(attributLang); nouedProg.AppendChild(noeudLang); noeudNom = doc.CreateElement("Nom"); noeudNom.AppendChild(doc.CreateTextNode("C")); noeudLang.AppendChild(noeudNom); priceNode = doc.CreateElement("Type"); priceNode.AppendChild(doc.CreateTextNode("Procédural")); noeudLang.AppendChild(priceNode); //Fin de Création des éléments, des attributs et des valeurs //Afficher le document XML dans le console doc.Save(Console.Out); } } |
0