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

ASP Discussion :

ASP et DomDocument


Sujet :

ASP

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

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2003
    Messages : 447
    Points : 173
    Points
    173
    Par défaut Modification d'un fichier XML en ASP
    Je voudrais savoir comment je pourrais faire pour modifier un fichier xml en asp ?

  2. #2
    Expert éminent
    Avatar de Immobilis
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2004
    Messages
    6 559
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 559
    Points : 9 506
    Points
    9 506
    Par défaut
    Salut Princemaster

    Fais une recherche sur XMLDOM.

    A+
    "Winter is coming" (ma nouvelle page d'accueil)

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

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2003
    Messages : 447
    Points : 173
    Points
    173
    Par défaut Soucis de vidage du Lecture.ReadLine
    je parviens à modifier mon fichier mais lors d'une nouvelle modification j'ai une erreur dû à mon avis à un soucis de vidage de mon paramètre Lecture.ReadLine, mon erreur est : "L'entrée dépasse la fin du fichier".

    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
     
     
         Set FSO = Server.CreateObject("Scripting.FileSystemObject") 
         FichierXml = GetDirWithoutLastDelimiter(REPWORK) &"\Cartes\CarteDeViste.xml"
         set Lecture = FSO.OpenTextFile(FichierXml,1,false) 
         For i=0 To DebutLigne - 2
          Line1 = Line1 & Lecture.ReadLine + vbCr 		
         Next 
     
         Lecture.skipLine 
         Lecture.skipLine
     
         While not Lecture.atEndOfStream				
          Reste = Reste + Lecture.ReadLine + vbCr		
         Wend
         Lecture.close						
     
         set Ecriture = FSO.OpenTextFile(FichierXml,2,false) 	
     
         Line2 = "   <position PosX="""& NewPosX &""" PosY="""& NewPosY &""" Align="""& NewAlign &"""/>"
         Line3 = "   <Police Italic="""& NewItalic &""" Gras="""& NewGras &""" Souligne="""& NewSouligne &""" Taille="""& NewTaille &""">"""& NewPolice &"""</Police>"
     
         Ecriture.writeLine Line1
         Ecriture.writeLine Line2				
         Ecriture.writeLine Line3
         Ecriture.writeLine Reste
         Ecriture.close				
     
         set Lecture=nothing
         set Ecriture=nothing
         set FSO=nothing

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

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2003
    Messages : 447
    Points : 173
    Points
    173
    Par défaut ASP et DomDocument
    Mon but est de remplacer des valeurs de mon fichier XML depuis une application ASP, pour cela je voudrais rechercher des attributs.

    Voici mon fichier XML :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
     
    <model_carte>
     <nom Largeur="90" Hauteur="52">Modele simple</nom>
     <img_background>CarteDeVisite\Logo\CarteDkRepro.gif</img_background>
      <elements>
       <element>
        <libelle Presence="1">Nom</libelle>
        <position PosX="400" PosY="200" Align="Center"/>
        <Police Italic="1" Gras="0" Souligne="0" Taille="10">Verdana</Police>
       </element>
       ...
    Je voudrais récupérer la valeur PosX="400" pour la remplacer par PosX="500"

  5. #5
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    166
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2004
    Messages : 166
    Points : 189
    Points
    189
    Par défaut
    explications à cette adresse : http://www.devguru.com/technologies/xml_dom/index.asp.
    Jette un coup d'oeil à : selectNodes, attributes, setAttribute et save

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

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2003
    Messages : 447
    Points : 173
    Points
    173
    Par défaut
    Je voudrais remplacer un attribut de mon fichier XML

    Voici mon fichier XML :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
     
    <model_carte> 
     <nom Largeur="90" Hauteur="52">Modele simple</nom>
     <img_background>CarteDeVisite\Logo\CarteDkRepro.gif</img_background>
     <elements>
      <element>
       <position PosX="400" PosY="200" Align="Center" Presence="1">Nom - Prénom</position>
       <Police Italic="1" Gras="0" Souligne="0" Taille="10">Verdana</Police>
      </element>
      ...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
     
     NomChamps = Request.QueryString("NomChamps")
     set Nodes=xmlDoc.selectNodes("/model_carte/elements/element/position[.='"& NomChamps &"']") 
     For each x in nodes
       'Set x.xml.Replace(10,10,"PosX=100")
     Next
    Voici la ligne du fichier xml concerné : Code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
     
    <position PosX="400" PosY="200" Align="Center" Presence="1">Nom - Prénom</position>
    Je voudrais remplacer mon attribut PosX="400" par PosX="100"

  7. #7
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    166
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2004
    Messages : 166
    Points : 189
    Points
    189
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
     
    objXMLDoc.load("??????.xml") 
    Set NodeList = objXMLDoc.documentElement.selectNodes("model_carte/elements/element/position ") 
    For Each Node In NodeList 
       att = Node.Attributes("PosX")
       if att=100 then
         Node.setAttribute(400)
       end if
    Next

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

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2003
    Messages : 447
    Points : 173
    Points
    173
    Par défaut Erreur
    J'ai une erreur sur la ligne "att = Node.Attributes("PosX")" qui est :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
     
    Type incompatible: 'attributes' 
     
    /Appli_ng/File.asp, ligne 96

  9. #9
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    166
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2004
    Messages : 166
    Points : 189
    Points
    189
    Par défaut
    c'est peut être getattribute qu'il faut utiliser alors et non attributes
    Un exemple ici http://www.devguru.com/technologies/xml_dom/15914.asp

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

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2003
    Messages : 447
    Points : 173
    Points
    173
    Par défaut exact mais ...
    il fallait bien utiliser un getAttribute mais mon deuxieme soucis se trouve dans le filtrage de mes noeuds.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
     
           Champs = "Nom"
           NewPosX = Request.QueryString("NewPosX")
     
           Set NodeList = xmlDoc.documentElement.selectNodes("/model_carte/elements/element/position[@text='"& Champs &"']")
     
           For Each Node In NodeList 
            'att = Node.getAttribute("PosX")
            Node.setAttribute "PosX",""& NewPosX &""
     
            'Sauvegarde dans le fichier XML des modifications apportées.
            'xmlDoc.save(GetDirWithoutLastDelimiter(REPWORK) &"\Cartes\CarteDeViste2.xml")
           Next
    Mon soucis est qu'avec se selectnode je ne rentre pas dans ma boucle

    Pour rappel, voici mon fichier xml :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
     
    <elements>
     <element>
      <position PosX="500" PosY="200" Align="center" Presence="1
    ">Nom</position>
      <Police Italic="1" Gras="0" Souligne="0" Taille="10">Verdana</Police>
     </element>
     ...

  11. #11
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    166
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2004
    Messages : 166
    Points : 189
    Points
    189
    Par défaut
    essaie avec
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Set NodeList = xmlDoc.documentElement.getElementsByTagName("position")

Discussions similaires

  1. connexion via asp ou php ?
    Par cege dans le forum 4D
    Réponses: 5
    Dernier message: 25/01/2006, 08h43
  2. [CR][ASP] interfaçage
    Par grosjej dans le forum SAP Crystal Reports
    Réponses: 2
    Dernier message: 15/04/2004, 10h20
  3. Erreur fréquente avec ASP et IIS
    Par Community Management dans le forum ASP
    Réponses: 2
    Dernier message: 11/02/2004, 22h20
  4. Que pensez vous du mariage ASP Flash?
    Par tyma dans le forum Flash
    Réponses: 4
    Dernier message: 09/07/2003, 15h00
  5. |VB6] [Réseau] Lancer une page ASP
    Par Delphi-ne dans le forum VB 6 et antérieur
    Réponses: 9
    Dernier message: 18/10/2002, 16h10

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