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
| Function Parse_XML_EVENT()
'Lire un XML récalcitrant.
'Nécessite la référence Microsoft XML v6.0 dans Tools/References
Dim xmlDoc As DOMDocument
Dim root As IXMLDOMElement
Dim i As Integer
Dim strFilename As String
strFilename = "C:\Temp\XmlTest1.xml"
Set xmlDoc = New DOMDocument
xmlDoc.async = False
xmlDoc.Load strFilename
Set root = xmlDoc.documentElement
'Voici le document XML que nous allons analyser:
Debug.Print root.XML
ParcoursEvent root
Set root = Nothing
Set xmlDoc = Nothing
MsgBox ("Fini")
End Function
Function ParcoursEvent(root_node As IXMLDOMNode)
'Dans Menu Tools/ references..., ajoutez Microsoft XML.
'Voici un exemple qui affiche dans la fenêtre de débogage la liste des balises contenues dans un document xml.
Dim i As Long
Dim strNodeValue As String
For i = 0 To root_node.childNodes.length - 1
If root_node.childNodes.Item(i).nodeTypeString <> "element" Then
strNodeValue = root_node.childNodes.Item(i).nodeValue
strNodeValue = Replace(strNodeValue, Chr(10), "")
Debug.Print root_node.parentNode.baseName, root_node.baseName, strNodeValue
Else
'Debug.Print root_node.baseName, "est un element :", root_node.nodeTypeString
End If
'Appel recursif de cette fonction
ParcoursEvent root_node.childNodes(i)
Next
End Function |
Partager