UiPath Activities

The UiPath Activities Guide

Read and Deserialize an XML file

The example below explains how to use activities such as Deserialize XML, Execute XPath, Get XML Nodes, or Get XML Node Attributes for reading, deserializing, accessing, and displaying various information about an XML file. You can find these activities in the UiPath.Web.Activities package.

📘

Note:

Download and extract the archive with the project in this example and copy the file daily_usd.xml to your project folder.

This is how the automation process can be built:

  1. Open Studio and create a new Process.
  2. Drag a Sequence container in the Workflow Designer.
    • Create the following variables:

Variable Name

Variable Type

Default Value

xml

String

xmlDeserialized

XDocument

xml_xpath_result

Object

xmlNodes

IEnumerable

xmlAttributes

IEnumerable

allExchRates

String

  1. Add a Read Text File activity inside the Sequence.
    • Add the expression "daily_usd.xml" in the File Name field.
    • In the Properties panel, add the variable xml in the Content field.
  2. Add a Deserialize XML activity below the Read Text File activity.
    • Add the variable xml in the XML String field.
    • In the Properties panel, add the variable xmlDeserialized in the XMLDocument.
  3. Add an Execute XPath activity below the Deserialize XML activity.
    • Add the variable xmlDeserialized in the Existing XML field.
    • Add the expression "string(/channel/lastBuildDate)" in the XPath Expression field.
    • In the Properties panel, add the variable xml_xpath_result in the Result field.
  4. Add a Message Box activity below the Execute XPath activity.
    • Add the expression "Exchange rates for " + xml_xpath_result.ToString in the Text field.
  5. Add a Get XML Nodes activity below the Message Box activity.
    • Add the variable xmlDeserialized in the ExistingXML field.
    • In the Properties panel, add the variable xmlNodes in the XMLNodes field.
  6. Add a Get XML Node Attributes activity below the Get XML Nodes activity.
    • Add the expression xmlNodes(0) in the Existing XML Node field.
    • In the Properties panel, add the variable xmlAttributes in the Attributes field.
  7. Add a Message Box activity below the Get XML Node Attributes activity.
    • Add the expression xmlAttributes(0).Name.Tostring + ": " + xmlAttributes(0).Value.Tostring in the Text field.
  8. Add an Assign activity below the Message Box activity.
  • Add the variable allExchRates in the To field.
  • Add the expression "Exhange Rates" + System.Environment.NewLine in the Value field.
  1. Add a For Each activity below the Assign activity.
  • Add the expression xmlDeserialized.Element("channel").Elements("item") in the Values field.
  • In the Properties panel, select the System.Xml.Linq.XElement option from the TypeArgument drop-down list.
  1. Add an Assign activity inside the Sequence container of the For Each activity.
  • Add the variable allExchRates in the To field.
  • Add the following expression in the Value field: allExchRates + System.Environment.NewLine + "1 " + item.Element("baseName").Value.ToString + " = " + item.Element("exchangeRate").Value.ToString + " " + item.Element("targetName").Value.ToString.
  1. Add a Message Box activity below the For Each activity.
  • Add the variable allExchRates in the Text field.
  1. Run the process. The XML file is read, deserialized, and accessed. A few message boxes are displayed with information extracted from the file.

Updated 3 months ago


Read and Deserialize an XML file


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.