Précédent   Forum des professionnels en informatique > Webmasters - Développement Web > Langages serveur > ASP
ASP Forum sur la programmation ASP. Avant de poster : Cours ASP, FAQ ASP
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 23/03/2007, 14h18   #1
Membre habitué
 
Développeur informatique
Inscription : octobre 2003
Messages : 448
Détails du profil
Informations personnelles :
Âge : 30

Informations professionnelles :
Activité : Développeur informatique

Informations forums :
Inscription : octobre 2003
Messages : 448
Points : 134
Points : 134
Par défaut Modification d'un fichier XML en ASP

Je voudrais savoir comment je pourrais faire pour modifier un fichier xml en asp ?
PrinceMaster77 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/03/2007, 14h42   #2
Expert Confirmé Sénior

 
Avatar de Immobilis
 
Inscription : mars 2004
Messages : 5 849
Détails du profil
Informations forums :
Inscription : mars 2004
Messages : 5 849
Points : 5 965
Points : 5 965
Salut Princemaster

Fais une recherche sur XMLDOM.

A+
Immobilis est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/03/2007, 12h40   #3
Membre habitué
 
Développeur informatique
Inscription : octobre 2003
Messages : 448
Détails du profil
Informations personnelles :
Âge : 30

Informations professionnelles :
Activité : Développeur informatique

Informations forums :
Inscription : octobre 2003
Messages : 448
Points : 134
Points : 134
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 :
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
PrinceMaster77 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/03/2007, 17h28   #4
Membre habitué
 
Développeur informatique
Inscription : octobre 2003
Messages : 448
Détails du profil
Informations personnelles :
Âge : 30

Informations professionnelles :
Activité : Développeur informatique

Informations forums :
Inscription : octobre 2003
Messages : 448
Points : 134
Points : 134
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 :
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"
PrinceMaster77 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/03/2007, 12h02   #5
Membre actif
 
Inscription : mai 2004
Messages : 166
Détails du profil
Informations personnelles :
Localisation : France

Informations forums :
Inscription : mai 2004
Messages : 166
Points : 178
Points : 178
explications à cette adresse : http://www.devguru.com/technologies/xml_dom/index.asp.
Jette un coup d'oeil à : selectNodes, attributes, setAttribute et save
amar00 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/03/2007, 12h20   #6
Membre habitué
 
Développeur informatique
Inscription : octobre 2003
Messages : 448
Détails du profil
Informations personnelles :
Âge : 30

Informations professionnelles :
Activité : Développeur informatique

Informations forums :
Inscription : octobre 2003
Messages : 448
Points : 134
Points : 134
Je voudrais remplacer un attribut de mon fichier XML

Voici mon fichier XML :

Code :
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 :
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 :
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"
PrinceMaster77 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/03/2007, 14h11   #7
Membre actif
 
Inscription : mai 2004
Messages : 166
Détails du profil
Informations personnelles :
Localisation : France

Informations forums :
Inscription : mai 2004
Messages : 166
Points : 178
Points : 178
Code :
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
amar00 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/03/2007, 14h35   #8
Membre habitué
 
Développeur informatique
Inscription : octobre 2003
Messages : 448
Détails du profil
Informations personnelles :
Âge : 30

Informations professionnelles :
Activité : Développeur informatique

Informations forums :
Inscription : octobre 2003
Messages : 448
Points : 134
Points : 134
Par défaut Erreur

J'ai une erreur sur la ligne "att = Node.Attributes("PosX")" qui est :

Code :
1
2
3
4
5
 
 
Type incompatible: 'attributes' 
 
/Appli_ng/File.asp, ligne 96
PrinceMaster77 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/03/2007, 17h44   #9
Membre actif
 
Inscription : mai 2004
Messages : 166
Détails du profil
Informations personnelles :
Localisation : France

Informations forums :
Inscription : mai 2004
Messages : 166
Points : 178
Points : 178
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
amar00 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/03/2007, 09h31   #10
Membre habitué
 
Développeur informatique
Inscription : octobre 2003
Messages : 448
Détails du profil
Informations personnelles :
Âge : 30

Informations professionnelles :
Activité : Développeur informatique

Informations forums :
Inscription : octobre 2003
Messages : 448
Points : 134
Points : 134
Par défaut exact mais ...

il fallait bien utiliser un getAttribute mais mon deuxieme soucis se trouve dans le filtrage de mes noeuds.

Code :
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 :
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>
 ...
PrinceMaster77 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/03/2007, 11h19   #11
Membre actif
 
Inscription : mai 2004
Messages : 166
Détails du profil
Informations personnelles :
Localisation : France

Informations forums :
Inscription : mai 2004
Messages : 166
Points : 178
Points : 178
essaie avec
Code :
Set NodeList = xmlDoc.documentElement.getElementsByTagName("position")
amar00 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 01h04.


 
 
 
 
Partenaires

Hébergement Web