关闭

vb对XML的读取

812人阅读 评论(0) 收藏 举报

自己的代码:
读出所有数据
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

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:109898次
    • 积分:1813
    • 等级:
    • 排名:千里之外
    • 原创:55篇
    • 转载:53篇
    • 译文:0篇
    • 评论:15条
    最新评论