meme06
Messages postés11Date d'inscriptionvendredi 8 septembre 2006StatutMembreDernière intervention11 mai 2009
-
2 mars 2009 à 18:27
mimosa803
Messages postés345Date d'inscriptionjeudi 15 février 2007StatutMembreDernière intervention24 avril 2010
-
26 mars 2009 à 13:00
j'ai un xml et je trouve pas comment inserer des données a l'interieur
Voila comment je fait en C# pour inserer un nouveau livre ou nouveau CD?
j'ai ce code pas mal mais il cree un nouveau genre au lieu d'inserer a l'interieur
// Value given for the new attribute
newcatalogattr.Value = "005";
// Attach the attribute to the xml element
newcatalogentry.SetAttributeNode(newcatalogattr);
// First Element - Book - Created
XmlElement firstelement = xmldoc.CreateElement("Book");
// Value given for the first element
firstelement.InnerText = "Peter";
// Append the newly created element as a child element
newcatalogentry.AppendChild(firstelement);
// Second Element - Publisher - Created
XmlElement secondelement = xmldoc.CreateElement("Publisher");
// Value given for the second element
secondelement.InnerText = "Que Publishing";
// Append the newly created element as a child element
newcatalogentry.AppendChild(secondelement);
// New XML element inserted into the document
xmldoc.DocumentElement.InsertBefore(newcatalogentry,xmldoc.DocumentElement.LastChild);
// An instance of FileStream class created
// First parameter is the path to our XML file - Catalog.xml
FileStream fsxml = new FileStream(path,FileMode.Truncate,FileAccess.Write,FileShare.ReadWrite);
// XML Document Saved
xmldoc.Save(fsxml);
Bon ca donne un resultat trés different de ma structure mais je trouve pas mal ce code je peu l'adapter mais au niveau de l'insertiont g un gros soucis a naviguer dans les noeuds.