1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| Dim docXML As XmlDocument = New XmlDocument()
docXML.Load(Application.StartupPath + "\berline.xml")
'On récupere le flux XML depuis le fichier XML
Dim docXMLFromLinq As XElement = XElement.Load(Application.StartupPath + "\berline.xml")
Dim nodes As XmlNodeList = docXML.SelectNodes("/voitures/berline")
'Utilisation de Linq to XML
'le fichier XML
Dim iMaxNodeId As Integer = 0
'docXMLFromLinq.Element("")
For Each id In docXMLFromLinq.Elements("voitures")
Dim iIdNode As Integer = System.Convert.ToInt32(id.Attribute("Mercedes"))
iMaxNodeId = Math.Max(iMaxNodeId, iIdNode)
Next
'Le nouveau noeud
Dim oNewNode1 As XElement = New XElement("berline", New XAttribute("id", iMaxNodeId + 1), New XElement("marque", "Mercedes"))
Dim oNewNode2 As XElement = New XElement("berline", New XAttribute("id", iMaxNodeId + 1), New XElement("dateachat", "01/01/2009"))
Dim oNewNode3 As XElement = New XElement("berline", New XAttribute("id", iMaxNodeId + 1), New XElement("immatriculation", "123ABC38"))
Dim oNewNode4 As XElement = New XElement("berline", New XAttribute("id", iMaxNodeId + 1), New XElement("kilometrage", "1000"))
'sauvegarde du fichier XML
docXMLFromLinq.Add(oNewNode1)
docXMLFromLinq.Add(oNewNode2)
docXMLFromLinq.Add(oNewNode3)
docXMLFromLinq.Add(oNewNode4)
docXMLFromLinq.Save(Application.StartupPath + "\berline.xml")
'attention Nom_de_projet : remplacer par le nom de votre projet
'Dim sDestinationSauvegarde As String = .Properties.Settings.Default.ModeleTypesDeFichier |