Pages: 1
Print
Author Topic: Does getNodesByXPath work differently in vb code from the macro?  (Read 843 times)
achu
Member

Posts: 39


« on: October 15, 2010, 03:47:53 PM »

What 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.5


here 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 If
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 1534



WWW
« Reply #1 on: October 15, 2010, 04:03:01 PM »

There 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.
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 1534



WWW
« Reply #2 on: October 15, 2010, 04:44:43 PM »

I'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

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 <section> 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 <section> 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.
« Last Edit: October 15, 2010, 04:48:33 PM by Derek Read » Logged
achu
Member

Posts: 39


« Reply #3 on: October 18, 2010, 08:20:11 AM »

instead of declaring as XMetaL.Application and XMetaL.Document, just declaring as object works well here.
Thanks!
Logged
Pages: 1
Print
Jump to:  

email us