IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Supprimer dans fichier XML


Sujet :

VB.NET

  1. #1
    Candidat au Club
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Avril 2014
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 60
    Localisation : France, Lot et Garonne (Aquitaine)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2014
    Messages : 4
    Points : 3
    Points
    3
    Par défaut Supprimer dans fichier XML
    Bonjour,

    Comment faire pour supprimer un noeud comme ceci :

    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <?xml version="1.0" encoding="utf-8"?>
    <lstSite>
      <Zone>
        <Page_Zone>xxxxxxxxxxxx</Page_Zone>
        <Nombre_de_pages_Zone>37</Nombre_de_pages_Zone>
      </Zone>
      <Liens_Zone>
        <L00>xxxxxxxxxxxxxxxxx/</L00>
      </Liens_Zone>
    </lstSite>

    Je voudrais supprimer <Nombre_de_pages_Zone> mais removechild ne fonctionne pas.

    Mon code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    Dim Name2 As String = "Page_Zone"
            Dim element As XmlNodeList
            Dim XmlDoc As XmlDocument = New XmlDocument()
     
            XmlDoc.Load(My.Application.Info.DirectoryPath & "\Réf Zone.xml")
            element = XmlDoc.DocumentElement.GetElementsByTagName("Zone")
     
            For Each noeud In element
                'For Each noeudEnf In noeud.ChildNodes
                '    If noeudEnf.LocalName = "Nombre_de_pages_Zone" Then
                '        'Name = noeudEnf.InnerText
                '        Name = noeudEnf.LocalName
                '    End If
                '    If Name = Name2 Then
                '        Console.WriteLine("Trouvé ..... " & Name)
                '        'XmlDoc.DocumentElement.RemoveChild(noeudEnf)
                '    End If
                'Next
     
            Next
     
            'Try
            '    'charge le fichier xml
            '    Dim doc As New XmlDocument
            '    doc.Load(My.Application.Info.DirectoryPath & "\Réf Zone.xml")
     
            '    'selectionne le noeud parent de l'élément à supprimer
            '    Dim root As XmlNode = doc.SelectSingleNode("/lstSite")
            '    'doc.SelectSingleNode("/lstSite")
            '    'selectionne l'élément à supprimer
            '    Dim elem As XmlElement = doc.SelectNodes("lstSite" & "/Page_Zone").ItemOf(1 - 1)
     
            '    'supprime l'élément
            '    root.RemoveChild(elem)
     
            '    'sauvegarde
            '    doc.Save(My.Application.Info.DirectoryPath & "\Réf Zone.xml")
     
            'Catch ex As Exception
            '    MsgBox("Erreur dans la suppression de l'élément : " & ex.Message)
            'End Try
     
     
            'Dim doc As New Xml.XmlDocument
            'doc.Load(My.Application.Info.DirectoryPath & "\Réf Zone.xml")
            ''doc.LoadXml(My.Application.Info.DirectoryPath & "\Réf Zone.xml")
            'Dim clientNodes = doc.SelectNodes("Page_Zone")
            'For Each elem As Xml.XmlElement In clientNodes
            '    If elem.InnerText = Name2 Then
            '        Console.WriteLine("Trouvé ..... " & elem.InnerText)
            '        'elem.ParentNode.RemoveChild(elem)
            '        Exit For
            '    End If
            'Next
            'MessageBox.Show(doc.OuterXml)

    Bon tout est en commentaire, car je ne sais pas quoi prendre.
    Bilou

  2. #2
    Expert confirmé
    Avatar de wallace1
    Homme Profil pro
    Administrateur systèmes
    Inscrit en
    Octobre 2008
    Messages
    1 966
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Administrateur systèmes
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Octobre 2008
    Messages : 1 966
    Points : 4 005
    Points
    4 005
    Billets dans le blog
    7
    Par défaut
    Bonsoir,

    Comme ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
      Dim XmlDoc As XmlDocument = New XmlDocument()
            XmlDoc.Load("D:\xml.xml")
            Dim ParentNode = XmlDoc.SelectSingleNode("/lstSite/Zone")
            Dim NodeToRemove = XmlDoc.SelectSingleNode("/lstSite/Zone/Nombre_de_pages_Zone")
            ParentNode.RemoveChild(NodeToRemove)
            XmlDoc.Save("D:\xmlNew.xml")
    ++

  3. #3
    Candidat au Club
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Avril 2014
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 60
    Localisation : France, Lot et Garonne (Aquitaine)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2014
    Messages : 4
    Points : 3
    Points
    3
    Par défaut Supprimer dans fichier XML
    Cool, je vais tester, un grand merci, je peut pas dire que tu m'a retiré une épine du pied, hier, ai marché sur un cactus
    Bilou

  4. #4
    Expert confirmé
    Avatar de wallace1
    Homme Profil pro
    Administrateur systèmes
    Inscrit en
    Octobre 2008
    Messages
    1 966
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Administrateur systèmes
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Octobre 2008
    Messages : 1 966
    Points : 4 005
    Points
    4 005
    Billets dans le blog
    7
    Par défaut

  5. #5
    Candidat au Club
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Avril 2014
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 60
    Localisation : France, Lot et Garonne (Aquitaine)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2014
    Messages : 4
    Points : 3
    Points
    3
    Par défaut Supprimer dans fichier XML
    Impec, encore merci
    Bilou

Discussions similaires

  1. Réponses: 4
    Dernier message: 28/10/2005, 09h59
  2. Balise html dans fichier XML
    Par pierrox dans le forum XML/XSL et SOAP
    Réponses: 3
    Dernier message: 19/09/2005, 09h20
  3. [XML] Incorporation de balises HTML dans fichier XML
    Par wazzzzza dans le forum XML/XSL et SOAP
    Réponses: 3
    Dernier message: 26/07/2005, 14h17
  4. [JDOM] Ajout élément dans fichier XML
    Par delinot dans le forum Format d'échange (XML, JSON...)
    Réponses: 4
    Dernier message: 18/07/2005, 11h10
  5. Pb de balises dans fichier XML
    Par allstar dans le forum XMLRAD
    Réponses: 2
    Dernier message: 10/06/2005, 13h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo