General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion Does getNodesByXPath work differently in vb code from the macro?

  • achu

    Does getNodesByXPath work differently in vb code from the macro?

    Participants 2
    Replies 3
    Last Activity 11 years, 8 months ago

    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

    Reply

    Derek Read

    Reply to: Does getNodesByXPath work differently in vb code from the macro?

    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.

    Reply

    Derek Read

    Reply to: Does getNodesByXPath work differently in vb code from the macro?

    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[/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.

    Reply

    achu

    Reply to: Does getNodesByXPath work differently in vb code from the macro?

    instead of declaring as XMetaL.Application and XMetaL.Document, just declaring as object works well here.
    Thanks!

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support