<img src="//trc.taboola.com/1222697/log/3/unip?en=page_view" width="0" height="0" style="display:none">


The Knowledgebase articles are deprecated. Please visit the new Guides and Resources here: https://www.uipath.com/developers/guides-and-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.


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


  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.


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.