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

VBScript Discussion :

VBScript ASP ET XMLDOM Modification attribut dans un fichier XML


Sujet :

VBScript

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2003
    Messages
    447
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2003
    Messages : 447
    Par défaut VBScript ASP ET XMLDOM Modification attribut dans un fichier XML
    Je voudrais savoir comment je pourrais faire pour modifier un attribut dans un fichier XML.

    Je parviens à lire toutes les informations de mon fichier, mais je ne parviens pas à y modifier un attribut, voici mon fichier XML :

    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
     
    <?xml version="1.0" encoding="UTF-8"?>
    <model_carte>
    	<nom Largeur="90" Hauteur="52" background="CarteDkRepro.gif">Modele simple</nom>
    	<elements Id="1">

    Je veux remplacer mon attribut "background"

  2. #2
    Expert éminent


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Par défaut
    s'il sagit d'un script.. .Vbs ... voir :

    Comment accéder aux attributs d'une balise ?

  3. #3
    Membre éclairé
    Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2003
    Messages
    447
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2003
    Messages : 447
    Par défaut Mauvaise compréhension
    Je parviens très bien a lire tous les noeuds et aller pointer vers un noeuds bien défini mais je ne parviens pas a en changer un attribut.

  4. #4
    Expert éminent


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008

  5. #5
    Membre éclairé
    Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2003
    Messages
    447
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2003
    Messages : 447
    Par défaut Mon Attribut n'est pas changé
    Mon fichier est bien sauvegarder, mais aucune modification n'y a été apportées, voici 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
     
     
     Dim objFSO 
     Dim xmlDoc,xmlPath,xmlNomModel,xmlTableUser,xmlTableAppli,node
     Set objFSO=Server.CreateObject("Scripting.FileSystemObject") 
     If objFSO.FileExists(GetDirWithoutLastDelimiter(REPWORK) &"\Cartes\CarteDeVisite.xml") Then
      set xmlDoc = nothing 
      set xmlDoc = Server.CreateObject("MSXML2.DOMDocument") 
      Test = xmlDoc.load(GetDirWithoutLastDelimiter(REPWORK) &"\Cartes\CarteDeVisite.xml")    
      If Test then 
       Set xmlPath = xmlDoc.documentElement
       If xmlPath.hasChildNodes() then
        If xmlPath.childnodes.item(0).text <> "" Then
         Set Noms = xmlPath.getElementsByTagName("nom")
         For Each Elem In Noms
          IdModel = Id
          Modele = Elem.childNodes(0).text
          ModeleLargeur = Elem.getAttribute("Largeur")
          ModeleHauteur = Elem.getAttribute("Hauteur")
     
          If Trim(ChoixModele) = Trim(IdModel) Then
           NomModel = Elem.childNodes(0).text
           CarteLargeur = Elem.getAttribute("Largeur")
           CarteHauteur = Elem.getAttribute("Hauteur")
           CarteImg = Elem.getAttribute("background")
     
           oElement = Replace(CarteImg, "CarteDeVisite\Logo\CarteDkRepro.gif", "CarteDkRepro.gif")
           Response.Write("oElement : "& oElement)
     
          End If
         Next
        End If 
       End If    
      End If   
     End If
     
     xmlDoc.save("D:\DocuRepro\Cartes\CarteDeVisite.xml")
     Set xmlDoc = Nothing

  6. #6
    Membre confirmé
    Inscrit en
    Juin 2005
    Messages
    275
    Détails du profil
    Informations forums :
    Inscription : Juin 2005
    Messages : 275
    Par défaut
    Etant donné que ton fichier XLM utilise UTF-8, peut-être pourrais-tu utiliser XSLT.

    Il existe en VBScript de quoi appliquer des modifications définies en XSLT sur un fichier XML.

    Ce n'est qu'une idée, je ne sais pas quelles sont les règles qui font que background doit changer. Toujours est-il que la sollution xslt fonctionnerait comme suit :

    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
    Sub lancerAdaptationXSLT(nomFichierInitial, nomFichierFinal, nomFichierXSLT)
        'déclaration et création des objets nécessaires à la fonction
        Dim oXml, oXsl, sortie, xslt, xslDoc, xmlDoc, xslProc
        Set oXml = CreateObject("MSXML2.DOMDocument.4.0")
        Set oXsl = CreateObject("MSXML2.DOMDocument.4.0")
        Set sortie = CreateObject("Scripting.FileSystemObject")
        Set fichierTemporaire = sortie.CreateTextFile(nomFichierFinal, True)
        oXml.validateOnParse = False
        oXml.async = False
        'chargement du fichier XML à transformer
        oXml.Load (nomFichierInitial) 'Attention au chemin du fichier
        If oXml.parseError.errorCode <> 0 Then
            MsgBox "erreur chargement XML : " & oXml.parseError.reason
        Else
            oXsl.async = False
            'chargement du fichier XSLT définissant les règles de transformation
            oXsl.Load (nomFichierXSLT)
            If oXsl.parseError.errorCode <> 0 Then
                MsgBox "erreur chargement XsL : " & oXsl.parseError.reason
            Else
            'application des transformations, que l'on écrit dans le fichier temporaire créé.
            fichierTemporaire.writeLine oXml.transformNode(oXsl.documentElement)
            fichierTemporaire.Close
            End If
        End If
        Set fichierTemporaire = Nothing
        Set sortie = Nothing
        Set oXsl = Nothing
        Set oXml = Nothing
    End Sub

  7. #7
    Membre éclairé
    Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2003
    Messages
    447
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2003
    Messages : 447
    Par défaut Cela me paret bien compliqué
    Cela me paret bien compliqué à mettre en place uniquement pour pouvoir chnager un attribut, n'y a t'il pas d'autres solution quite même à utiliser autre chose que UTF-8.

  8. #8
    Membre confirmé
    Inscrit en
    Juin 2005
    Messages
    275
    Détails du profil
    Informations forums :
    Inscription : Juin 2005
    Messages : 275
    Par défaut
    Tu dis parcourir tous les noeuds pour pouvoir changer la valeur de certain de leurs attributs. Ce qui est exactement un des principes de XSLT.

    Je ne dois donc pas avoir bien compris ton objectif :

    - combien d'attributs veux-tu modifier dans ton ficher ? je pensais comprendre que plusieurs fois dans le même fichier, tu voulais changer background, mais la est peut etre mon erreur.
    - la structure de ton fichier XML est-elle figée ?

  9. #9
    Membre éclairé
    Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2003
    Messages
    447
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2003
    Messages : 447
    Par défaut non désoler
    Non désoler tu as tres bien compris mon soucis , je veux bien changer un attribut dans mon fichier XML mon soucis est que je ne connais pas trop le XSLT avec ASP, mais peut etre pourrais tu me donner plus de détail pour réaliser mon changement d'attribut ?

Discussions similaires

  1. comment je pourrais modifier un attribut dans un fichier xml
    Par ryoussef19 dans le forum Visual C++
    Réponses: 6
    Dernier message: 24/08/2007, 14h16
  2. Réponses: 1
    Dernier message: 20/02/2007, 13h43
  3. Réponses: 3
    Dernier message: 29/06/2006, 16h54
  4. Affecter un attribut dans un fichier XML ou XSL
    Par LLaurent dans le forum XMLRAD
    Réponses: 7
    Dernier message: 05/06/2003, 14h04
  5. Lire un attribut dans un fichier XML en C++
    Par ti.k-nar dans le forum XML
    Réponses: 2
    Dernier message: 14/10/2002, 15h22

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