Xml file with xmlns value

Hi, I’m working with an xml file showed in the image above:
Captura

As you can see, the Element (second line) has an xmlns value.

I’m trying to obtain the value of the Element . These are the steps of my develope:

  1. Assign to a variable called xDoc (XDocument Type) the value XDocument.Load(“My xml file”)

  2. Assign to a variable called ElementCollection (system.collection.generic IEnumerable of XElement) the value xDoc.Descendants("Jv-Ins-Reinsurance ")

  3. For each elem in ElementCollection, Write Line elem.value

The problem is that I’m not obtaining any value in ElementCollection and, If I delete the attributes of Jv-Ins-Reinsurance, it works perfectly. But I need to mantain this attributes

Can you help me, please?

I,ve tried to upload the xml file but I couldn’t because I’m a new user.

Thank you all¡¡

Hi,

Can you try the following steps.

First, define System.XML.Linq.XNamespace type variable (Let’s say xns) and set namespace which is defined the element in xmlns attribute to it.

xns = "http://xxxxxxxxxx"

Then the following will work.

xDoc.Descendants(xns+"Jv-Ins-Reinsurance ")

Regards,

1 Like

Some illustrations to @Yoichi mention

Hi,

First of all, thank you very much for your answer.

I’m getting crazy… so I need help from people like you…

I’ve attached a .rar file with the .xml file and the .xaml process I’m traying to do.

I need to get the value of the Element “Cedent Reference” marked in yellow in the image above

With this value, I’ll get another value from a Data Table and I had to replace the text “Please advise” (rounded in red in the image) with the value obtained in Data Table

But I’m not being able to get the first value and I think the problem is the namespaces in the root line.

As you can see in the xaml, I’m getting one only element and I don’t know if I’m doing something wrong.

Please, can you give me some help?

Thank you in advance!!

David (a novice RPA Developer)

(Attachment PRUEBA XML.rar is missing)

Sorry, I attached a .rar file and it`s not allowed.

I`m attaching now a .7z file

Thanks!

PRUEBA XML.7z (47.1 KB)

Hi,

One of the roughest ways is to use “ReinsurerReference” directly, as the following.

If there is possibility there are multiple ReinsurerReference element (including parent element), need to get TechAccount elements first, then Contract elements, finally ReinsurerReference element.

Regards,

Thank you again Yoishi,

But I’m afraid that it doesn’t work.

As you can see above, no results obtained in my output panel

Hi,

In my environment it works well. Can you check the xml is same as the attached one?

And, for now, can you try the following sample as it is?

PruebaXML2.zip (4.0 KB)

Regards,

1 Like

Yes, it works!!!

The problem was in the .xml file as you told me.

Thanks a lot!!

David

1 Like

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