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
- Read the XML document
- Deserialize the document
- Use a loop to iterate through repetitive elements
- Read the XML document just like a simple text file by using ReadTextFile activity that outputs a string. This string must be deserialized.
- 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.
- 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.