PB selectSingleNode et validation xsd avec msxml/xpath
Bonjour,
Je développe une routine pour récupérer des paramètres de configuration dans un fichier xml. cette routine tourne sur un serveur windows sous traité seul msxml peut être utilisé.
Mon besoin :
- Valider la configuration avec un schéma Xsd.
- Utiliser Xpath pour récupérer les paramètres.
Après tests 8O:
Mes requêtes XPath fonctionne si j'utilise la version de base avec un progid "MSXML2.DOMDocument". selectSingleNode renvoi toujours null meme avec un simple ->selectSingleNode("/node")
dans mon code :
Set Conf = xmlDoc.selectSingleNode("/Configuration/Profile[@Id='" & ProfileName & "']")
En fesant des recherches sur d'autre site j'ai vu que le version 1 de msxml gère XPath 1.0 puis que la version 2 gère un nouveau language de selection de noeud appelé XSL Pattern et c'est dans la version 3 que XPath et XSL Pattern sont implémenté. J'ai activé XPath avec la ligne suivant :
Code:
xmlDoc.setProperty "SelectionLanguage", "XPath"
mais sans résultat.:cry:
Pour la validation c'est le contraire, cela ne fonctionne qu'avec un prodId a partir de "MSXML2.DOMDocument.4.0" à "MSXML2.DOMDocument.6.0"
Lorsque j'utilise MSXML2.DOMDocument avec MSXML2.XMLSchemaCache j'ai une erreur d'automation lors de l'ajout du schéma avec la fonction add :
objSchemas.Add sNamespace, xsdDoc
Ma routine de conf :
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
| Public Function Configuration()
'initialise la function log désactivé au démarrage
ActiveLog = False
Logger "Validation de la config..."
Dim xsdDoc
Dim sNamespace
Dim objSchemas
Dim oErr
Set xsdDoc = CreateObject("MSXML2.DOMDocument.4.0")
xsdDoc.async = False
If (xsdDoc.Load("C:\Documents and Settings\led\Bureau\Spie\SyncWebDav.xsd")) Then
'Validation XSD
'Ajoute le namespace
sNamespace = xsdDoc.documentElement.getAttribute("targetNamespace")
Set objSchemas = CreateObject("MSXML2.XMLSchemaCache.4.0")
If Err.Number <> 0 Then
Logger "Echec - Chargement du composant MSXML2.XMLSchemaCache"
Configuration = False
Exit Function
End If
objSchemas.Add sNamespace, xsdDoc
Logger "Chargement de la config..."
Dim xmlDoc
Dim Conf
Set xmlDoc = CreateObject("MSXML2.DOMDocument.4.0")
xmlDoc.validateOnParse = True
xmlDoc.async = False
xmlDoc.resolveExternals = True
xmlDoc.setProperty "SelectionLanguage", "XPath"
If xmlDoc.Load("C:\Documents and Settings\led\Bureau\Spie\SyncWebDav.xml") Then
Set xmlDoc.Schemas = objSchemas
Set oErr = xmlDoc.validate
If (oErr.errorCode <> 0) Then
Logger "Echec n° " & oErr.errorCode & ", " & oErr.reason
Configuration = False
Exit Function
End If
Dim ProfileName
ProfileName = xmlDoc.documentElement.getAttribute("ProfileAUtiliser")
'Test profile
Set Conf = xmlDoc.selectSingleNode("/Configuration/Profile[@Id='" & ProfileName & "']")
'Obtient le profile configuré
'Authentification utilisateur (identifiant+mot de passe)
Dim UtilisateurConf
Set UtilisateurConf = xmlDoc.selectSingleNode("/Configuration/Profile[@Id='" & ProfileName & "']/Authentification/Utilisateur")
If (UtilisateurConf Is Nothing) Then
sUserName = ""
sPassword = ""
Else
sUserName = UtilisateurConf.Text
Dim PassConf
Set PassConf = xmlDoc.selectSingleNode("/Configuration/Profile[@Id='" & ProfileName & "']/Authentification/MotDePasse")
If (PassConf Is Nothing) Then
sPassword = ""
Else
sPassword = PassConf.Text
End If
End If
'Fonctionalité à activer
Dim FonctionsConf
Set FonctionsConf = xmlDoc.selectSingleNode("/Configuration/Profile[@Id='" & ProfileName & "']/Fonctions")
If (FonctionsConf Is Nothing) Then
'Valeurs par défaut
ActiveLog = True
ActiveSuppr = False
Else
ActiveLog = (LCase(FonctionsConf.getAttribute("Log")) = "oui")
ActiveSuppr = (LCase(FonctionsConf.getAttribute("SuppressionMirroir")) = "oui")
End If
Dim ServerLANGConf
Set ServerLANGConf = xmlDoc.selectSingleNode("/Configuration/Profile[@Id='" & ProfileName & "']/LangueServWebDav")
SERVER_LANG = ServerLANGConf.Text
'SERVER_LANG = "FR"
Dim DestinationConf
Set DestinationConf = xmlDoc.selectSingleNode("/Configuration/Profile[@Id='" & ProfileName & "']/Destination")
ServerUrl = DestinationConf.getAttribute("Serveur")
BaseFolderWD = DestinationConf.getAttribute("DossierBase")
Dim SourceConf
Set SourceConf = xmlDoc.selectSingleNode("/Configuration/Profile[@Id='" & ProfileName & "']/Source")
BaseLocalPath = SourceConf.getAttribute("Chemin")
Dim LogConf
Set LogConf = xmlDoc.selectSingleNode("/Configuration/Profile[@Id='" & ProfileName & "']/Log")
If (LogConf Is Nothing) Then
LogFilenamePath = ""
If (ActiveLog) Then
ActiveLog = False
Logger ("Log désactivé ! Pas de chemin renseigné dans la section Configuration/Profile/Log")
End If
Else
'Définition du fichier de log
LogFilenamePath = CombinePath(LogConf.getAttribute("Chemin"), "Log-" & Year(Date) & Month(Date) & day(Date) & Hour(Now) & Minute(Now) & Second(Now) & ".txt", "\")
End If
'Chemin du fichier contenant la table de correspondance
'entre Html et CharSet (ex: %20 -> espace)
Dim CharToHtml
Dim HTMLVersCar
Set HTMLVersCar = Conf.selectSingleNode("/Configuration/HTMLVersCar")
CharToHtml = HTMLVersCar.Text
'initialise les tables de caractere pour faire la traduction entre html et charset
InitializeHtmlToChar CharToHtml
Configuration = True
Else
Configuration = False
Logger "Echec lors du chargement de la configuration"
End If
Else
Configuration = False
Logger "Echec lors du chargement du schéma de configuration"
End If
Set xmlDoc = Nothing
Set xsdDoc = Nothing
End Function |
Mon xml :
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 32 33 34 35 36 37 38
|
<?xml version="1.0" encoding="utf-8"?>
<Configuration ProfileAUtiliser="monprofile" xmlns="urn:schemas-spie-com-syncWebDav">
<!--ATTENTION L'ORDRE DES BALISES DOIT ETRE RESPECTE-->
<Profile Id="monprofile">
<!--Language prise en charge par le serveur WebDAV
Valeur possible : FR, EN-->
<!--Active la suppression des fichiers sur le mirroir webDav qui n'existe plus dans la source-->
<!--<Authentification>
<Utilisateur>XXXXXXXX</Utilisateur>
<MotDePasse>xxxxxxxxx</MotDePasse>
</Authentification>-->
<!--<Fonctions SuppressionMirroir="Non" Log="Oui" />-->
<LangueServWebDav>EN</LangueServWebDav>
<Destination Serveur="https://xxxx" DossierBase="/xxx/" />
<Source Chemin="C:\Test\Data" />
<Log Chemin="C:\Test\Log" />
</Profile>
<Profile Id="workflow">
<!--Language prise en charge par le serveur WebDAV
Valeur possible : FR, EN-->
<!--Active la suppression des fichiers sur le mirroir webDav qui n'existe plus dans la source-->
<LangueServWebDav>FR</LangueServWebDav>
<Fonctions SuppressionMirroir="Oui" Log="Oui" />
<Destination Serveur="http://workflow" DossierBase="/testwebdav/" />
<Source Chemin="C:\Test\Data" />
<Log Chemin="C:\Test\Log" />
</Profile>
<!--Utilisé par la conversion des url en chemin FS et vice versa-->
<HTMLVersCar>
<![CDATA[%C3%87 Ç
%C3%BC ü
%C3%A9 é
%C3%A2 â
%20 ]]>
</HTMLVersCar>
</Configuration> |
J'aimerai pouvoir faire une validation et des requetes XPATH.
Je suis a votre disposition pour toutes précisions
Merci.