Bonjour,
- Bonne Année 2011 et Bonne Santé -
Une problématique récurente : l'insertion de variable(s) dans une instruction.
Précision : Le code est (doit être) en VBScript. Les réponses dans d'autres langages (VB, Net, ...) ne servent à rien.
L'instruction : SelectSingleNode (string).
La problématique :
- Si le "string" est codé "en dur", cela fonctionne impec.
- Si une partie du "string" est composé d'une variable, cela ne fonctionne pas.
En cause (interprétation perso.) : des guillemets mal interprétés (bug ?)
J'utilise l'EDI VBScript Factory et suit sous XP (bientôt sous Seven).
Diverses recherches sur le Net ne m'ont pas aidé à résoudre ce problème.
Certes, je pourrais utiliser SelectNodes avec un Do While, mais je suis têtu et veux utiliser SelectSingleNode.
Pourriez-vous m'aider à résoudre mon problème ?
D'avance, merci.
Cordialement.
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 Option Explicit '--- Permet d'éviter les erreurs "bêtes" c.a.d les noms des variables mal réécris (erreur de frappe) Dim XmlAlerte, Node, Truc, Machin Set XmlAlerte = Createobject("Microsoft.XMLDOM") XmlAlerte.Async = False XmlAlerte.Load("Alertes_source.xml") Set Node = XmlAlerte.DocumentElement.SelectSingleNode("Composants/Obj_Type") ' ok Msgbox "N01 " & Node.Text Set Node = XmlAlerte.DocumentElement.SelectSingleNode("Composants[Obj_Type='Switch']") ' Ok Msgbox "N02 " & Node.Text Truc = "WM4" Machin ="Composants[@Obj_Nom='" & Truc & "']" Set Node = XmlAlerte.DocumentElement.SelectSingleNode(Machin) ' Msgbox "N03 " & Node.Text ==> sort en erreur ' ======> La variable Truc n'est pas prise en compte correctement Set Node = XmlAlerte.DocumentElement.SelectSingleNode("Composants[@Obj_Nom='" & Truc & "']" ) If Node Is Nothing Then Msgbox "N04 " & "vide" Else Msgbox "N04 " & Node.Text End If Set Node = XmlAlerte.DocumentElement.SelectSingleNode("Composants[@Obj_Nom='VM4']" ) ' Ok If Node Is Nothing Then Msgbox "N05 " & "vide" Else Msgbox "N05 " & Node.Text End If Set Node = XmlAlerte.DocumentElement.SelectSingleNode("Composants[@Obj_Nom='VM4']/Obj_Type") ' ok If Node Is Nothing Then Msgbox "N06 " & "vide" Else Msgbox "N06 " & Node.Text End If
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 <?xml version="1.0" encoding="utf-8"?> <Alertes> <Composants Obj_Nom="VM4"> <Obj_Type>Serveur</Obj_Type> <Obj_Statut>Down</Obj_Statut> <Obj_couleur>Rouge</Obj_couleur> <Obj_NowOFF>21/12/2010 15:30:00</Obj_NowOFF> <Obj_Cause>Serveur</Obj_Cause> <Obj_Comment>Pas de réponse au Ping</Obj_Comment> </Composants> <Composants Obj_Nom="VM2"> <Obj_Type>Serveur</Obj_Type> <Obj_Statut>Down</Obj_Statut> <Obj_couleur>Rouge</Obj_couleur> <Obj_NowOFF>21/12/2010 15:30:00</Obj_NowOFF> <Obj_Cause>Serveur</Obj_Cause> <Obj_Comment>Pas de réponse au Ping</Obj_Comment> </Composants> <Composants Obj_Nom="VM2S"> <Obj_Type>Serveur</Obj_Type> <Obj_Statut>Down</Obj_Statut> <Obj_couleur>Orange</Obj_couleur> <Obj_NowOFF>21/12/2010 15:30:00</Obj_NowOFF> <Obj_Cause>Serveur</Obj_Cause> <Obj_Comment>Pas de réponse au Ping</Obj_Comment> </Composants> <Composants Obj_Nom="172.17.1.174"> <Obj_Type>Switch</Obj_Type> <Obj_Statut>Down</Obj_Statut> <Obj_couleur>Rouge</Obj_couleur> <Obj_NowOFF>21/12/2010 15:30:00</Obj_NowOFF> <Obj_Cause>Inondation</Obj_Cause> <Obj_Comment>Installation sous l'eau</Obj_Comment> </Composants> </Alertes>
Partager