General XMetaL Discussion
XMetaL Community Forum › General XMetaL Discussion › Does getNodesByXPath work differently in vb code from the macro?
-
achu October 15, 2010 at 9:47 pm
Does getNodesByXPath work differently in vb code from the macro?
October 15, 2010 at 9:47 pmParticipants 2Replies 3Last Activity 12 years, 5 months agoWhat I attempt to implement is to let the use specify the file name and section number in VB.NET UI program(not a dll, out of process) to open a xml document in XMetal. by achieving this, i added XMetal reference to the VB program.
However, I got stuck at the line with getNodesByXPath. the program complains about the invalid xpath expression. When I tested the same xpath expression in macro, I got the desired result.
any idea why the vb program doesn't work?'==============
XMetal version 5.5here is my vb code
Dim XMApp As New XMetaL.Application
Dim currDoc As XMetaL.Document = XMApp.Documents.Open(XMLFilename)
Dim xpathPointer As String = “.//section[enum='802.']/enum”currDoc.Activate()
If Not currDoc.getNodesByXPath(xpathPointer) Is Nothing Then
XMApp.Selection.SelectBeforeNode(currDoc.getNodesByXPath(xpathPointer).item(0))
End IfDerek Read October 15, 2010 at 10:03 pm
Reply to: Does getNodesByXPath work differently in vb code from the macro?
October 15, 2010 at 10:03 pmThere should be no difference. I would expect exactly the same behavior with any language no matter how an API is called (in a macro in JScript/VBScript/Perl/Python or through COM as you are doing).
The only thing I can think of is that the string is not being passed through properly for some reason, but the code at first glance seems to be OK.
Derek Read October 15, 2010 at 10:44 pm
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
and I think removing that complexity for now is best anyway). Can you get something like this working? 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.
-
AuthorPosts
- You must be logged in to reply to this topic.