Using XML data to get values

Hi all

I’m trying to learn how to read and iterate though XML data using .element and .attribute and then for each loops e.g trying things like ‘XMLData(my variable).Element(“data”).Element(“columns”).Attribute(“Age”).ToString’
but I’ve noticed the XML data is set up slightly differently to what I’ve seen in that it has columns information then records (as opposed to ‘just records’.) So I’m guessing I could reference the ‘desired column index’ to get the info I need but I’m not sure how to do this.

Appreciate it’s a big ask but could anybody please guide me on what I would write to get specific data like a persons first and last name or their country.

Thanks for the help,
Jordan

Can you share the XML @jordrowley, so that I will try and get back to you

The method you were using right and is the actual way of getting XML attribute value
Hmm do you mean like you need to access them with some other method

Cheers @jordrowley

New_Assignment1.zip (666 Bytes)

@HareeshMR thanks for getting back to me. Here it is :slight_smile:

Jordan

Hey @Palaniyappan

Thanks for replying. I wondered if there was a way you could use data from the ‘columns’ section to get the corresponding info required, if that makes sense.

Jordan

This is something I explained in a previous forum post.

Attached is an example workflow which uses an XML file detailing some football fixture information. it provides the beginnings of how you access the data using UiPath.

IterateXML.zip (4.3 KB)

Thanks @ronanpeter - I will take a detailed look shortly and try and achieve the desired results with my XML.

Appreciate the explanation too.

Jordan

@jordrowley,

If you want the particular tag values, then Use this

xmlDoc.Element(“data”).Element(“columns”).Element(“Age”).Value

And if you want to iterate through all the child tags inside the columns and rows, here is the attachment.

XMLChallenge.xaml (14.4 KB)

1 Like

Hi @HareeshMR,

Thank you so much for this. Runs really well and plenty for me to learn from. I’m going to see if I can split the data for each person (for example ‘38Canada15/10/2017DulceFemale15522Abril’) in to it’s constituent parts and put it all in an array or datatable, something like that under the correct column headings. Please can I ask, would you recommend the best way to do this is to split the records up in to an array then add them to a datatable with the column headers already set? or would you approach this a different way?

Thanks again :smile:
Jordan

That was a great question and it is very exciting to answer.

You have two ways to do that.

  1. you can directly write the columns as columns into Excel and data in the respective rows using Excel activities by just looping as the above workflow

Or

  1. you can use build data table activities and add the headings of the columns using add data column and the respective data of the entire record using add data rows…

Try using these methods

XMLChallenge.xaml (28.1 KB) XmlTextValue.xaml (14.2 KB)

Hey @HareeshMR,

My colleague helped me look at the XML xaml you’d kindly built for me and had a play around with it. Here is the output which gets the data and puts it in to a datatable ready for an excel file, just in case you want to take a look :slight_smile:
Thanks again
Jordan

Thank you @jordrowley,

It helps the forum users if any one wants to do the same…

The thing is, as per the forum rules, we are not supposed to provide the workflows as a solution. But explaining the design of a XML workflow is difficult. So, i added the workflow but writing it to an excel is an easy thing. So, I just guided you to do that :slight_smile:

@jordrowley

Thanks again

1 Like

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