Bonsoir, pour tester j'ai mis ce fichier "voitures.xml"dans l'application sous bin->Debug :
<?xml version="1.0" encoding="utf-8" ?> <voiture> <ferrari> <name ch="240">f4</name> <name ch="240">f5</name> <name ch="240">f6</name> </ferrari> </voiture>
Un bouton pour tester Private Sub btnSupprVoiture_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnSupprVoiture.Click SupprDataVoitureXML("voitures.xml", "f5") End Sub
et la procédure Sub SupprDataVoitureXML(ByVal pathFichier As String, _ ByVal voiture As String) Dim xmldoc As New Xml.XmlDocument() xmldoc.Load(pathFichier) Dim xpathVoitures As String = "/voiture/ferrari" '*** Création d'un chemin, pour la recherche de l'élément à supprimer. Dim xpath As String = xpathVoitures & "/name[text()=""" & voiture & """]" Dim xmlElem As Xml.XmlNode = xmldoc.SelectSingleNode(xpath) '*** Si il existe, tordu, on recherche son parent pour tuer son enfant. If xmlElem IsNot Nothing Then xmlElem.ParentNode.RemoveChild(xmlElem) xmldoc.Save(pathFichier) End If End Sub Bonne soirée.
|