How to create an RPA Flow using Invoke Method activity with System.Xml.XmlDocument
Overview
The Invoke Method activity in Infor RPA allows you to execute methods from .NET classes directly within your automation flows. This powerful feature enhances flexibility by enabling automation of complex tasks beyond standard activities. It also promotes reusability, allowing you to leverage existing .NET libraries and code, reducing duplication and ensuring consistency across systems and applications. By integrating .NET methods, you can simplify intricate operations that involve advanced logic or multiple steps while maintaining efficiency and consistency across automation projects.
In this tutorial, we will focus on using the Invoke Method activity with the System.Xml.XmlDocument class from the .NET Framework. The XmlDocument class provides methods for working with XML data, including loading XML, selecting nodes, and retrieving node values.
We will start by reading a TXT file containing an XML structure, then load the XML string into an XmlDocument object, select a specific XML node, and retrieve its value.
Components
- RPA
- RPA Studio
- RPA management
- .Net Framework
Key Components for using Invoke Method for XML document
- XmlDocument: A .NET class used for handling XML data. It supports various operations like loading, querying, and modifying XML content.
- SelectSingleNode: A method of the XmlDocument class that selects a single node based on an XPath expression.
- InnerText: A property of the XmlNode class used to retrieve the text content of an XML node.
Requirements
- You need to install the latest version of RPA Studio on your machine:
- Download the connection files
- Download RPA Installer from RPA Management. For this tutorial you need to install:
- IDE Studio
- Establish a connection between the RPA Studio and the RPA Management
- You can check the Infor RPA Studio User Guide for the details
- Basic Understanding of XML: Familiarity with XML structure and XPath expressions is useful.
- .NET Framework Knowledge: Basic understanding of .NET classes and methods is beneficial.
- TXT file to be created an saved: e.g. C:\RPA\Example.txt
- XML Data: Copy the code below in a text file and save it as Example.xml in the same location that you saved the previously created Example.txt file. (e.g. C:\RPA\Example.xml).
<Root>
<Element id = "1">Value1</Element>
<Element id = "2">Value2</Element>
</Root>
Tutorial
Difficulty: Medium
Estimated completion time: 35 Minutes
1. Open RPA Studio
Open RPA Studio on your machine, and sign in, if required.
2. Create a new project
On the Home page click Create New Project and specify the following properties in the pop up window:
- Name: InvokeMethodExample
- ProjectLocation: <default>
- Description: Demo on the Invoke Method with xml document manipulation
- Language: VB <selected by default>
3. Start building the Sequence
First, we will read the XML file into a string using the Read Text File activity. You can find the list of activities by clicking Activities in the left-hand side bar or from the View menu in the top bar. Use search to find the activity you want.
Configure the activity in the following way:
- Source FilePath: Set this to the path of your XML file (e.g., “C:\RPA\Example.xml”).
- Text: To store the content of the xml file, let’s create a variable for the Text property. We’ll call it xmlContent, the Variable type is string.

4. Add and Configure Assign Activity
Next, we will create an xmlDocument object using the Assign activity, which should be configured in the following way:
- Create a variable to store the result for To property. Name it xmlDoc and choose the type System.XML.XMLDocument (Variable type/Browse for Types).
- Go back to the Assign activity and add the variable xmlDoc to To property.
- Value: New System.Xml.XmlDocument()
- This makes the eExpression:
xmlDoc = New System.Xml.XmlDocument()
.

5. Add and configure the Invoke Method Activity
We will now load the XML content into the xmlDocument using the Invoke Method activity, which should be configured in the following way:
- Target Object: Set this to
xmlDoc
(theXmlDocument
object). - Method Name: We will call this LoadXML as we are loading the XML content.
- Set the Parameters by clicking the “…” and configure in a following way:
- Direction:
In
. - Type:
String
. - Value: Set this to
xmlContent
(the string containing the XML content from step 1).
- Direction:

6. Add and configure the second Invoke Method
To find the element with id="1"
, we will use XPath via the SelectSingleNode
method, which should be configured in the following way using the Invoke Method activity:
- Target Object: Set this to
xmlDoc
. - Method Name: Use
SelectSingleNode
to search for the node. - Parameters:
- Direction:
In
. - Type:
String
. - Value: Set this to the XPath expression
"/Root/Element[@id='1']"
- Direction:
- Result: Store the result from the invoke method meaning the value of the node, for that we need to create the variable called
selectedNode
of type:Systen.XML.XmlNode
.

7. Add and configure the 3rd Invoke Method
Finally, we will extract the inner text (value) of the selected node using another Invoke Method activity. Create the required variable and fill in the InvokeMethod according to the image:

8. Finish the flow
You can output the results using Message Box activity. Add nodeValue Variable to Input Text.

Save your flow and Click Run to execute and verify that the output displays the value “Value1”.
Flow Improvement
If you want to write the values from the XML file into a text file at the end of the process to make sure they have been properly recorded, you can add an Append Line activity to the end of the flow.
- Line use the following expression xmlDoc.OuterXml
- Source Filepath specify the path of the file “C:\RPA\Example.txt“

Next Save and run the flow. You can then check the Example.txt file for the results.