How to extract attribute of a tag present in xml using uipath?

I have a xml file. I have “Attributes” tag in “UiTree”->“UiTreeNode”->“Children”->“Attributes” (Even though their is a “Attributes” tag in “UiTree”->“UiTreeNode” I don’t need it.). So in this “Attributes” tag I have multiple “Attribute” tags with a attribute inside it. Now I want the values aria-label and text attribute values present in attribute tag which is in i.e., from each “Attributes” I want to extract aria-label and text simultaneously. Some times text might not be present (aria-label is present always) at that time I want it to display as an empty string. Can anyone help with this? (The below attachment is the xml file that I am using.)

UiTree.xml (62.5 KB)

Hi!

Maybe xpath will do the trick?
Take a look at this post

Hi @Vyshnavi_Nalumachu ,

Please Try this
image
Xpath Expression and Properties
image
image

Hope this helps.!

Thanks,
Gautham

1 Like

Sorry @ sven.wullum1 I didn’t get a clear understanding from it. And here aria-label and text are attributes of “Attribute” tag so I need the values of a attribute not the text between the tags

Hi @Gautham_Pattabiraman When I tried to print the arialabel value I got the output as

image

Can you please share your workflow?

Hi @Vyshnavi_Nalumachu <

That is cause Xpath activity returns op of type object.

Currently checking on options to convert that into string array or list or any iterable formats

Will attach the solution shortly

1 Like

Okay @Gautham_Pattabiraman. Thank you

the use case description has some unclear parts and we would also recommend to include the expected output format / datatype.

However we assume that technically it should be implementable

RnD / Prototype

item = xDoc.Root.Element("UiTreeNode").Element("Children").Descendants("Attributes")
attr = {"aria-label","text"}
log: 
item.XPathSelectElements(String.Format(".//Attribute[@{0}]",attr)).Select(Function (x) x.Attribute(attr).Value).FirstOrDefault()

will have an output:

we can see with the yellow marks the non present attribute handling, which is returning a string default value

Hi @Vyshnavi_Nalumachu ,

Attaching the sample solution.

I have iterated through the output of XPath and created a list of values for the aria tag, But you can manipulate it according to your need with this as reference.

ForumQuestion.zip (7.7 KB)

Phew…It took a while, Frankly this is a new learning for me as well.

Thanks for the question.

Happy Automating…Hope this helps you…!

Thanks,
Gautham.

1 Like

@Vyshnavi_Nalumachu ,

Is the solution working out for you.?

The solution is good but only aria-labels could be extracted but I also wanted text tag too. And I want aria-labels and text tag simultaneously.

But still thank you for the help and the active replies I was able to learn new things from them

Let me check that as well for you will get back in sometime.

@Gautham_Pattabiraman Thank you for offering help! I actually got solution from @ppr comment. But I appreciate your willingness to assist. If you want to give me another solution you are always welcome

1 Like

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