Sunday, June 17, 2012

Parse XML Menggunakan Visual Basic 6.0

Sub ParseXmlDocument()
Dim doc As New MSXML2.DOMDocument
Dim success As Boolean

success = doc.Load(App.Path & "\test.xml")
If success = False Then
MsgBox doc.parseError.reason
Else
Dim nodeList As MSXML2.IXMLDOMNodeList

Set nodeList = doc.selectNodes("/Report/Categories/Category")

If Not nodeList Is Nothing Then
Dim node As MSXML2.IXMLDOMNode
Dim name As String
Dim value As String

For Each node In nodeList
' Could also do node.attributes.getNamedItem("name").text
name = node.selectSingleNode("@name").Text
value = node.selectSingleNode("@value").Text
Next node
End If
End If
End Sub