Deserialize XML

How can we use Deserialize activity in UiPath.

This is required to extract multiple fields like, Personal Number, First Name, last name etc and assign to variable so that it can be used further in processing a request. Below is content of XML file

<eservice name="PermissionForLeave">
  <field id="GF.7.1.1">
  <field id="GF.7.1.2">
  <field id="GF.7.1.3">
  <field id="GF.7.1.4">
    <answer>Testgatan 23</answer>
  <field id="GF.7.1.5">
    <answer>123 45</answer>
  <field id="GF.7.1.6">
  <field id="GF.7.1.7">
  <field id="GF.7.1.8">
  <field id="GF.7.1.9">
  <field id="U.7.2.1">
    <question>Personnummer </question>
  <field id="U.7.2.2">
    <question>Elevens förnamn</question>

This should help: How to iterate and read xml documents

The key is to use For Each loops to get all similar elements.
Sample here

1 Like


Step 1. Write a xml, I have below xml file,

Step 2. Take a activity called “ReadTextFile”, provide xml file path. it has properties called Content, create a String variable.

Step 3. Take a “Deserialize Xml” activity, provide that String variable to XmlString property & Create variable type XmlDocument.

Step 4. Display/print content of xml in message box/write line, write below statement,
"Question: " + DeserializeStrConfig.Element(“eservice”).Element(“field”).Element(“question”).Value
"Answer: " + DeserializeStrConfig.Element(“eservice”).Element(“field”).Element(“answer”).Value

Output will look like,
Question: Personnummer
Answer: 194112249166


Where can we see this Deserialize Activity?

just type “Deserialize Xml” in the activity panel.

It is not showing up by default. Which package does it require?

@Tiramisu You have to install UiPath.Web.Activities package.


Does anyone have a best practice idea for how to take the output of such activity and put it into a single line in Excel or CSV? So for example if my XML has:

I would want it to then return column1 = INVOICE, column 2 =LINE, column 3 = AMOUNT

and then each row has data.

I try to do as explained here, but I’m only getting the error:

Main has thrown an exception

Source: Write line

Message: Object reference not set to an instance of an object. This error usually occurs when using a variable with no set value (not initialized).

Exception Type: NullReferenceException

Now I’m getting this error:

An error has occured

Source: System.Xml

Message: Unable to cast object of type ‘Newtonsoft.Json.Linq.JValue’ to type ‘System.String’.

Exception Type: InvalidCastException

Please share the files with us that you’re using

Will this work for HTML as well? I am trying to send the following in an “SMTP Send Mail Message” ( with the “Is Body HTML” ), and am getting errors. It either shows the variable but not the plain text, or else I can get it to show the plain text but not interpret the variable. I am currently passing it as a String and thought maybe I was going about it wrong. Thoughts?

”+Hi, Welcome To Pen Pals,+‘"+firstChildsName.toString+’“+has been matched!”


Here is the excel doc that I am using, as well as the UI Path Flowchart. Thanks for any and all insights or help! :smile: Pen Pals 2018-JOSH-TEST.xlsx (60.6 KB)
SelectingRowsFromExcelMain.xaml (23.4 KB)

1 Like

Hi ,

Please find below tutorials