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 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.
(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