自己的代码:
读出所有数据
Public Function XmlRead(SKType As String, LeftOrRight As String)
Dim XMLDoc As DOMDocument ' main object for creating new views
Set XMLDoc = CreateObject("Microsoft.XMLDOM") 'New MSXML2.x ' XMLDocument
Dim oXML, oXMLRoot, oXMLItems
If Not XMLDoc.Load("New.xml") Then
MsgBox "度取XML失败"
'ValidateWorkFiles = ERR_GEN
Exit Function
End If
Dim iNodeLength As Integer
a = XMLDoc.selectSingleNode("Data/Ritht_Left_Data/Punting/Right")
procDispDatas a.childNodes
procDispDatas XMLDoc.childNodes
Set XMLDoc = Nothing
End Function
Sub procDispDatas(objNode)
Dim obj
For Each obj In objNode
If obj.NodeType = 3 Then 'And obj.parentNode.nodeName = "title" Then
'MsgBox obj.parentNode.nodeName & " : " & obj.nodeValue
Debug.Print obj.parentNode.nodeName & " : " & obj.nodeValue
End If
Dim temp As String
temp = obj.selectSingleNode("Data/Ritht_Left_Data/Punting/Right/Attribute_Name/text()").Value
If obj.hasChildNodes Then
procDispDatas obj.childNodes
End If
Next
End Sub
---------读取某个节
Dim iNodeLength As Integer
iNodeLength = XMLDoc.selectSingleNode("Data/Ritht_Left_Data/Punting/Right").childNodes.length
For i = 0 To iNodeLength - 1
Debug.Print XMLDoc.selectSingleNode("Data/Ritht_Left_Data/Punting/Right").childNodes.Item(i).nodeName
Debug.Print XMLDoc.selectSingleNode("Data/Ritht_Left_Data/Punting/Right").childNodes.Item(i).Text
Next