Add XML Node Uipath

Hey there

I have an XML document in which I have to run a bunch of rules on its nodes and attributes.

One of the rules requires the removal of a node. I managed to do that with the “Invoke Method” activity using the “Remove” Method.


Another rule requires the addition of a node and I am not being able to do it. I tried using the “Invoke Method” activity with the method “AddAfterSelf” but I am not finding a way to do it properly.


Can anyone help?

Best Regards

Try passing the value by creating the new instance i.e., @Pedro_Tavares

xelem.AddAfterSelf(new xelement(“artigo”))

1 Like

Thank you so much for such a quick response.

Should I try that on the “invoke method” activity?


If I have not explained myself correctly, what I want to do is Add node “artigo” in the XML

      "Add artigo node here"

I hope you can directly do that in the assign activity as well @Pedro_Tavares,

Iterate through the xml you have and try as

XDocument = XDocument(“root value”).Element(“value”). … .AddAfterSelf(new XElement)

please try and let me know :slight_smile:

Weird, it is still not working.

Yes this is a different error @Pedro_Tavares,
Please try with the Invoke Method itself and check if it is working

If you are updating a property, then you can do it in an assign activity. However, .AddAfterSelf is a method so you’ll need to do it in invoke method

TargetObject should be item.Element(“yourelement”).element('yourelement)
MethodName should be AddAfterSelf
Parameters: In (of type XElement) = New Xelement(“yourelement”)

Of course you’ll need to replace the “yourelement” with actual values - i was just too lazy to type it out from your screenshot since I couldn’t simply copy+paste :slight_smile:

It works with Invoke Method. :grinning:

The New XElement() has to be an input parameter in the Invoke Method, jus as @Dave says.

Thanks you guys for your help!

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