Thursday, June 7, 2012

VB6 Code - Mengevaluasi XPath dengan XPath Checker

Berikut adalah kode VB6 yang digunakan untuk mengevaluasi XPath yang digunakan untuk melakukan query terhadap file XML:
Option Explicit 

Private Sub
cmdEvaluate_Click()

On Error GoTo
ErrHandler

txtErrorXpath.Text = ""

Dim
doc As MSXML2.DOMDocument60
Dim nlist As MSXML2.IXMLDOMNodeList
Dim node As MSXML2.IXMLDOMNode

Set
doc = New MSXML2.DOMDocument60

doc.setProperty "SelectionLanguage", "XPath"
doc.loadXML txtXMLSource.Text

Set
nlist = doc.selectNodes(txtXPath.Text)
lblMathcing.Caption = "Matching Nodes : " & nlist.length

lstMatchingFound.Clear

For Each
node In nlist
lstMatchingFound.AddItem node.nodeName & " : " & node.Text
Next

Exit Sub

ErrHandler:

lstMatchingFound.Clear
txtErrorXpath.Text = "Error: " & Err.Description

End Sub