activities
latest
false
UiPath logo, featuring letters U and I in white
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.

Properties

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.

Example of Using the Execute XPath Activity

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:

  1. Open Studio and create a new Process.

    Note: Make sure to place the .xml file inside the project folder. For this example we used the XMLfiles.txt.
  2. Drag a Sequence to the Workflow Designer.

    • Create the following variables:

      Variable Name

      Variable Type

      Default Value

      XMLString

      String

       

      Result

      Object

       
  3. 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.
  4. 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 the xml file.
    • Add the variable Result in the Result field.
  5. Drag a Write Line activity after the Execute XPath activity.

    • Add the expression "Result: " + Result.ToString in the Text field.
  6. Run the process. The robot extracts the name of the author from the .xml file and displays it in the Output panel.
  • Properties
  • Example of Using the Execute XPath Activity

Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.