XML creation from data table and template Error


This is a follow-up question to my previous post at XML creation from data table and template.

I wanted to parse an XML file in UiPath and convert it to a data table, which I was able to achieve using the solution provided in the linked post.

I want to fetch the values and <failurereason/description> and <To/Phonenumber> from the XML file. I am getting object reference not set to an instance of the object" error. I assume that this is because when the “Status=failed”, the XML has a value for <failurereason/description>, but when the “Status=Delivered”, the tag <failurereason/description> is empty.

I’ve attached a sample parsed XML output. Can you please let me know how to get the failure description into the datatable when status=failed.


Please let me know if anyone has a solution for this?

Hi @ammohan,
can you share with us you statement that return error also if available share the XML text file it will be better that image :slight_smile:

Sample xml.txt (3.4 KB)

Hi @mahmoud.zaky ,

Please find a sample file attached.
This is the code that I am using for de-serializing the XML input where the dt_temp datatable has 3 columns “Phone Number” and “Status” and “Failure Reson”.

I am getting the error “object reference not set to an instance of an object” when I run the highlighted assign activity. This is because “failurereason” tag is only present when there is a “status”=“failed”. When status =“delivered”, the tag is not present.

As I my XML file is huse I cannot loop in and check for each case if “failurereason” tag is present.

Let me know if you have a solution.


give a try at following rewriting:

(From m in serialisedResponse.Descendants(XNSValue + "messageheader")
Let to = m.Descendants(XNSValue + "phonenumber").First().Value
Let st= m.Descendants(XNSValue + "status").First().Value
Let hasCode = m.Descendants(XNSValue + "code").Any()
Let cd = IF(hasCode,  m.Descendants(XNSValue + "code").First().Value, nothing)
Let ra = new Object(){to,st,cd}
Select r = dt_Temp.Rows.Add(ra)).CopyToDataTable

Should that be in invoke code?