Dim XmlDoc As XmlDocument = New XmlDocument() Dim declaration As XmlDeclaration = XmlDoc.CreateXmlDeclaration("1.0", "UTF-8", Nothing) Dim files As XmlNode = XmlDoc.CreateNode("element", "files", "") Dim principal As XmlNode = XmlDoc.CreateNode("element", "principal", "") Dim node As XmlNode = XmlDoc.CreateNode("element", "sha1", "") node.InnerText = "10000" principal.AppendChild(node) files.AppendChild(principal) For x = 0 To 3 Dim file As XmlNode = XmlDoc.CreateNode("element", "file", "") Dim node1 As XmlNode = files.AppendChild(file) Dim filename As XmlNode = XmlDoc.CreateNode("element", "filename", "") filename.InnerText = x.ToString Dim sha1 As XmlNode = XmlDoc.CreateNode("element", "sha1", "") sha1.InnerText = (x + 100).ToString node1.AppendChild(filename) node1.AppendChild(sha1) files.AppendChild(node1) Next XmlDoc.AppendChild(files) XmlDoc.InsertBefore(declaration, files) XmlDoc.Save("monfichier.xml") MsgBox("Enregistrement réussi")
XmlDoc.Load("http://www.monsite.fr/test.xml")
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionDim XmlDoc As XmlDocument = New XmlDocument() Dim elemSite As XmlElement elemSite = XmlDoc.CreateElement("SITE") 'creation et definition de la balise url (enfant) Dim elemUrl As XmlElement elemUrl = XmlDoc.CreateElement("URL") elemUrl.InnerText = " http://www.peuw.net/index.xml " 'creation et definition de la balise Nom (enfant) Dim elemNom As XmlElement elemNom = XmlDoc.CreateElement("NOM") elemNom.InnerText = "peuw.net" 'ajout des 2 balise enfants a la balise parent elemSite.AppendChild(elemUrl) elemSite.AppendChild(elemNom) 'on ajoute la balise parent au document XmlDoc.DocumentElement.AppendChild(elemSite) 'Ecriture du Xml XmlDoc.Save(Application.StartupPath & "Newsite.XML") MsgBox("Enregistrement réussi")
XmlDoc.DocumentElement.AppendChild(elemSite)
Object reference not set to an instance of an object.
XmlDoc.DocumentElement
XmlDoc.DocumentElement.AppendChild(elemSite)
Object reference not set to an instance of an object.