Hi All,
Currently i am working on a XML file which looks like this

the demand of the desirable output is like
i want to replace some incorrect data from tag

with correct data

i tried many solution but did not worked, there is a namespace i tried to work with namespace manager that also not worked.
tried to convert xml into datatable got the below error
Xml to data table: ‘tns’ is an undeclared prefix. Line 1, position 2.

when i deserialize the XML i get the same error.

Can anyone know the other solution for my question??
Any help would be appreciated.

Thanks in Advance
Pradyumn Agrawal

let us break down step by step and try to get it solved.

When you deserialze the XML string with the deserialize activity you will get back Datatype XDocument.
For with dealing with namespaces on a XDocument you have to work with XNamespaces.

Have a look here:

so in a first step I would suggest to identify a XML element of interest, setup the XNamspaces as done in the sample from link above and retrieve the element.

Once this is working we can go the next step.

Before doing any action check that your XML is valid and without any structure isues, as this will disturb the work

1 Like

Demo xamls should not be opened directly.
Download the xaml into your UiPath Project.
Ensure the dependency Manager is configured to reference UiPath.Web.Activities.

Can you tell me what will be my xdoc.element()

i have attached the screenshot of the xml file in starting

what is the output of xDoc.Root.Name


Ok then use this in

this the test if we can access the root. If this is working then setup the XNamespace for this namespace and check if you can access the root element with xDoc.Element(yournamspacevar+“CollaborationProtocolAgreement”).Name.toString

I normally printed the xdoc.Element in write line

i got the below error


this is my namespace variable and its defualt value

but when i pass the argument like this

i get the below output

ensure tha nscase variable has the highest scope and is valid on every place

Yes, it is on flowchart level and valid on every place

i will have a look on it after my jobwork.
maybe you share the xml with us


I am sharing my xml and XAML file

Exchange_Automation.zip (36.4 KB)

Your namespace was wrong initialized.

It has to look like this:

No { } and never the root local name. then it is working

And this was also the logic about the first tester lines:

I have made the changes now my namespace variable is valid and working fine.

What should be our next step to replace the element from tag < KeyInfo> < /KeyInfo>
with upper < KeyInfo>< KeyInfo> tag.

so now the detail requirement / task is to define.

with upper < KeyValue>< KeyValue> tag.

I didn’t get this

In general it has to check how many different KeyValue Tags will exist? You can start to setup to retrieve the on more KeyValue Tags.

Kindly note I will have a lot sessions, so expect some delays in my answers

The main idea behind this automation is to replace the incorrect data with Correct one.
There is one incorrect certificate in the XML and i have to replace with correct certificate.
The correct one lies just above the incorrect one
i have given you XML file if you check from line 937 to 974 (Open in Notepad++) is the correct data between <ds:keyinfo > < /ds:Keyinfo>

and from line 977 to 1006 is the incorrect data between < KeyInfo> </ KeyInfo>

rest of the data in file will remain same only this piece of information will be change
i mean incorrect part will be removed and we have to copy from < ds:Keyinfo></ds:Keyinfo > and paste in place of removed part.
Note: KeyInfo tags contain all the information which we need.

I hope you understand what i am trying to achieve, Please let me know if you any doubt

Please have a check on this next version. Download it into your UiPath project and reassign the FilePath to xml according to your end

Xaml here: Main_V2.xaml (14.5 KB)