Extract attribute from XML with namespace

Hello,

I need help to extract, for example, the yellow coloured field from XML Namespace:

I am trying this method: xmlDocument.Element(str_Url+“decisiondocument”).Element(str_Lab1+“block”).Element(str_lab2+“subdictionary”).Element(str_lab3+“v”).Attribute(“PasoAPaso”).Value

I am trying different access methods but I can’t find a way to extract the field, can someone please help me?

@Yur
as the element of interest is very on top you can analyse access options by following

  • set a breakpoint after XML serializing
  • debug and get the bot paused
  • open immediate panel and type in: YourXDocVar.Root.Descendants()(0).Name
  • increase the index 0,1,2,3… till you will get the element of interest

from the returned name you can derive the constraints for access
{xxx}elementname - xxx represents the value needed for the XNamespace

Kindly note: Element(str_Lab1+“block”) will have no return as name is a common attribute but not defining a namespace

use in last Descendants(id)

Hello!

Could you show me an example, please.

Hello, Peter,

Thank you very much for your reply.

I have applied your instruction but it is only useful in case I want to access the information through its index…

Do you know how I could access each field through the Key of the label?

For example, do you know how I could access the record number 28 that I colour in the attached image?

Thank you.

@Yur
the access by index was only to find out the element names and its details (using namespace or not, which value has the namespace part).

Maybe you can share with us results from
YourXDocVar.Root.Descendants()(X).Name with X=0,1,2,3

Based on this we can help you to loop over the different subdictionary elements with the help of Descendants method within a dynamic approach.

Maybe you can share also sample xml with us.

Hello,

Thank you very much for your reply.

I attach an image showing how using the statement YourXDocVar.Root.Descendants()(X).Name with X=0,1,2,3…we access the existing tag at each level, but it does not allow us to extract the value of the required tag:


M2__20210611_100808.xml (25.6 KB)

I also attach the XML file in case you would like to do some testing, Peter.

Thank you very much.

@Yur
with test by index on the names we do see, that the element name without any namespace info can be used.

Have a look on following flow just iterating dynamily over all elements from all subdictionarties and its contained v elements.


item = xDoc.Root.Descendants(“subdictionary”).toList
for each settings:
grafik

first log message:
String.Format("Process subdict: {0} Name: {1}", idx1, item.Attribute("name").value)

e = item.Descendants().toList

second log message:

String.Format("Element: {0} with id: {1} has value: {2}", e.Name.toString, e.Attribute("id").Value, e.Value)

we do not know what in details is planned for extracting values. But also have a look on following method:
grafik

find starter help here:
XMLStarter.xaml (7.9 KB)

Hey @ppr ,

Thank you very much for your help in solving this problem. Without a doubt the xaml you provided helped me a lot to understand the solution you were proposing.

Thank you very much again :wink: