Resources

Knowledge Base

How to iterate through and read XML documents

  • To be able to run this example you need to install UiPath. WebAPI.Activities.
  • See more details on how to install packages here.

Task

Get data from an XML document.

Steps to automate

  1. Read the XML document
  2. Deserialize the document
  3. Use a loop to iterate through repetitive elements

Solution

  1. Read the XML document just like a simple text file by using ReadTextFile activity that outputs a string. This string must be deserialized.
  2. For deserialization you have to use the DeserializeXml activity. The input for this activity is a string and the output is an XDocument. The XDocument contains the information necessary for a valid XML document. This includes an XML declaration, processing instructions, and comments.
  3. Basically an XML document is made from tags, attributes and elements. In the following picture our XML document is described.

XML_001.png

As you can see the root element is called "DOSSIER" and it has an attribute called TYPE. Each INVOICE has a number of elements and one of them is called INVOICELINE. INVOICELINE has three more elements therefore you need 2 loops, one inside another.

Poza1.png