Problem with XML elements

I have a problem with extracting data from XML elements and write them in an excel file.

Here is the XML.

IOM_XML_Utkast.docx (16.2 KB)

ill have a For Each where i iterate through the elements and extracts the data and write it in Excel.

Now to the problem. There is 2 Legs and i can only fetch the data from 1 Leg (the second Leg)

How can i fetch the data from both Legs?

Cheers
Milo

@Majlopajlo
we cannot see the deatils of your xml. Maybe you can share the sample xml file, a screenshot or using the editor format option </>

One important question is, if the XML is defining namespaces.

lets assume the xml looks like this in the structure:
xDoc:

  • root
    • leg
      • e1
      • e2
    • leg
      • e1
      • e2

retrieve all legs with xDoc.Root.Descendants(“leg”).toList - retuned: List(Of XElement) xeLegs

iterate over xeLegs within a for each and setup the element retrieval ( in this demo: e1,e2)

also have a look here:

1 Like

@ppr I have updated my post with the XML.

Thank you for your swift response

//Milo

@Majlopajlo
perfect.
I assume the fragment is surrounded by a root element (otherwise we can inject / fix it, before parsing)

As written above: the xDoc.Root.Descendants(“Legs”).toList will help for the iteration.

Let us know your open questions

2 Likes

@ppr
thank you. Now i got an error.

XML error.docx (365.3 K

@Majlopajlo
better is, to help us on native languguage error messages that we can understand.

It looks like leglist is of datatype XElement but should be of datatype List(Of XElement) as we do expect many legs

@ppr
Sorry for the language error. But you solved my problem anyway :slight_smile:

I dont really understand how i should iterate through the Leglist using your demo.

sorry for my endless questions. Im a newbie on robotics :slight_smile:

give me a liitle time an will do some helper for you

Of course…

@Majlopajlo
Variables:

Parsing & Legs retrieval:
grafik

iteration:

Output:
grafik

find starter help:
XMLDescendantsDemo.xaml (7.2 KB)

Sample XML:
DescendantsDemo.xml (636 Bytes)

Kindly note: the xml has to be valid and requires a root element, In the sample XML the root was manually added

Could not find type ‘DeserializeXml’ in namespace ‘http://schemas.uipath.com/workflow/activities’. Row: 61, Column: 6
which package should I have to install peter ?

UiPath.WebAPI.Activities

1 Like

@ppr
Absolutely brilliant. Thank you.

@ppr

Can you please elaborate your String. I dont know how to break it down in order to transfer the data to an Excel sheet.

String.Format(“Leg: {0} # Element: {1} # Value: {2}”,idx.toString, item.name,item.Value)

From output:
Leg: 0 # Element: CarrierCode # Value: QR ( how can i transfer this data to a specific cell)

Cheers

@Majlopajlo
in general do following:

  • define a datatable structure with the columns: legID, Key, Value - Build Datatable activity

  • additional to the logging use add datarow activity and define for rowArray: new Object(){dx.toString, item.name,item.Value}

  • the resulting datatable can be written to Excel with write range activity

Have also a look on the provided links / referenced posts as well.

In case of you need more individual help for your case, please share follwoing with us:

  • detailed descriptions of the resulting output (e.g. an excel with sample data)
  • how the dynamics should be handled (1…n legs, 1…n leg child elements)

Thanks

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.