Reading XML File with Fluent and VB

Hello all,

Has somebody used XML files in VB?

I’ve been asked to look into using XML files as data source either to be used directly in script or processed through VB and load results to script. I tried writing a simple VB code, but the script calling the VB code fails at the line where I declare a variable as XmlDocument (I imported System.XML at the top of the code). Code fails at the very first XML-related line of code.

Can somebody point me in the right direction?

Thanks.

Has somebody used XML files in VB?

Yes! You can use VB to parse all of the XML files on the Tecan for example. The tricky party is figuring out the namespace and then the nodes you want to query.

If you want to share your code maybe we can help.

Here’s what my code looks like:

Imports Microsoft.VisualBasic
Imports System
Imports Tecan.Core.Scripting
Imports System.XML

Public Class Public Class TestClass
    Implements IScriptObject

    Private Host As IScriptingHost

    Public Property ScriptingHost() As IScriptingHost Implements IScriptObject.ScriptingHost
        Get
            Return Host
        End Get
        Set(ByVal value As IScriptingHost)
            Host = value
        End Set
    End Property

    Public Sub Execute() Implements IScriptObject.Execute

        Dim errMsg As String =  ""

        Try

            Dim xDoc As XmlDocument

        Catch ex As Exception
            errMsg = "Error...."

        End Try

    End Sub

End Class

The error occurs at the declaration statement (Dim xDoc As XmlDocument). When I disable it, call from script completes without error.

I have done XML handling in VBA, and can navigate around nodes and elements, but here, it won’t even go past variable declaration. Am I making a fundamental mistake here?

Anyway, I thought of just using RegEx if can’t go further with this, although with RegEx, the XML file creation part might present another set of challenges. But, hey, one step at a time…

Does this compile? I noticed you have Public Class listed twice.

@luisvillaautomata

Sorry, it must have been the copy-paste. The one I have only has one “Public
Class” and runs without error if I disabled the line Dim xDoc as XmlDocument.

One of the potential causes I looked into was that I used Visual Studio Code on the computer connected to the instrument. However, when I tried it on another computer with the regular Visual Studio, I still get the error.

Solomon,

I was able to replicate the problem and I think I understand the issue now. Is the XML requirement rigid? If so, the fastest solution is to execute a Python script that converts the XML into a CSV and then you can parse that CSV with VB if it’s particularly nasty or you can import parameters from that CSV through one of the Programming commands. (My personal preference is to always use VB tho).

You can also call Python scripts from a VB. I have some old code laying around for that.

Here’s a good thread: Tecan Fluent & Python

Edit: There is another way but I would need to test it.

1 Like

@luisvillaautomata

The XMLs are generated in the upstream processes and what is being looked into is a change in the upstream process or use XML files with no changes, with the latter looking like the option with less work and validation.

The XML files are small and simple enough that I was able to get initial success with RegEx (before I was asked to prioritize something else). I’ll definitely keep Python in mind, just in case.