activities
latest
false
- Overview
- Cryptography
- Database
- Java
- Python
- WebAPI
Execute XPath
Developer Activities
Last updated Oct 22, 2024
Execute XPath
UiPath.WebAPI.Activities.ExecuteXPath
Executes the specified XPath expression on a given XML document. For more information on XPath syntax, go here.
Input
- ExistingXML - An XDocument variable containing the XML to be processed. Completing this field makes the XMLString field unusable. This field supports only XDocument variables.
- XMLString - A string or string variable containing the XML to be processed. Completing this field makes the ExistingXML field unusable. This field supports only strings and string variables.
- XPathExpression - A string or string variable that contains an XPath expression. This field supports only strings and string variables.
Misc
- Private - If selected, the values of variables and arguments are no longer logged at Verbose level.
Common
- DisplayName - The display name of the activity.
Output
- Result - An Object variable containing the retrieved nodes or node-sets of the given XML. This field supports only Object variables.
The Execute XPath activity is used for reading and extracting data from
.xml
files.
To exemplify how to use this activity, we have created an example that uses the Execute XPath activity for extracting the name of a person from a
.xml
file.
This is how the automation process can be built:
-
Open Studio and create a new Process.
Note: Make sure to place the.xml
file inside the project folder. For this example we used theXMLfiles.txt
. -
Drag a Sequence to the Workflow Designer.
-
Create the following variables:
Variable Name
Variable Type
Default Value
XMLString
String
Result
Object
-
-
Drag a Read Text File activity inside the sequence container.
- In the Properties panel, add the name
Read XML file
in the DisplayName field. - Add the value
"XMLfiles.txt"
in the FileName field. - Add the variable
XMLString
in the Content field.
- In the Properties panel, add the name
-
Add an Execute XPath activity after the Read Text File activity.
- In the Properties panel, add the variable
XMLString
in the XMLString field. - Add the value
"string(/catalog/book/author/text()[1])"
in the XPathExpression field. This expression extracts the text found in the author field from thexml
file. - Add the variable
Result
in the Result field.
- In the Properties panel, add the variable
-
Drag a Write Line activity after the Execute XPath activity.
- Add the expression
"Result: " + Result.ToString
in the Text field.
- Add the expression
-
Run the process. The robot extracts the name of the author from the
.xml
file and displays it in the Output panel.