Home › Forums › General XMetaL Discussion › Does getNodesByXPath work differently in vb code from the macro? › Reply To: Does getNodesByXPath work differently in vb code from the macro?
Reply to: Does getNodesByXPath work differently in vb code from the macro?
October 15, 2010 at 10:44 pmI've changed your code to get it working as there were quite a few missing bits in your example (the value for XMLFileName etc). I'm using VS 2010 in case that makes a difference as well. I have one button on a form and the following:
[code]Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim XMApp As Object = CreateObject(“XMetaL.Application”)
Dim XMLFileName As String = “C:test.xml”
Dim currDoc As Object = XMApp.Documents.Open(XMLFilename)
Dim xpathPointer As String = “.//section”
currDoc.Activate()
Dim foundNodes = currDoc.getNodesByXPath(xpathPointer)
XMApp.MessageBox(“Nodes: ” & foundNodes.length, 64, “Message in XMetaL”)
MessageBox.Show(“Nodes: ” & foundNodes.length, “Message in VB”)
XMApp = Nothing
End Sub
End Class[/code]
I didn't have a sample document or DTD, so rather than trying to set that up to be exactly like yours I've used a DocBook file at C:test.xml which has
elements in it and I get the right number of nodes returned (the length value). Note that I've also simplified the XPath (because DocBook doesn't have an @enum on
Note: If you are launching XMetaL from an external process you might wish to use the API called Application.InitComplete to be sure the startup process has finished before your code continues. See the Programmer's Guide for details.