Working with XML in UIPath

I have an xml file… I want to load it in UIPath and update some values. The approach I’m taking is
Step 1 - First read xml file as string
Step 2 - De Serialize that as xmlobject
Step 3 - Execute Xpath to get the value of the element
Step 4 - Update the value for that element
Step 5 - Write xml back to file.

In the above Step 1 and Step 2 - Completed without any issues
Step 3 - I’m able to successfully execute Xpath but how do i read the element ?
Setp 4 & Step 5 - how to update the xml element and write it back to file… can anyone throw some suggestions…

thanks

1 Like

Hi,

  1. Read Text File → Get xml file content as string
  2. DeSerialize string to XDocument
  3. & 4. You can access the value myXDoc.Root.Element(“myElement”).Value
    If you want to change said value you can assign string value to it : myXDoc.Root.Element(“myElement”).Value = “new value”
    5 Write Text File → overwrite the previous xml file or create a new one with value myXDoc.ToString

BR,
Topi

2 Likes

Hi
What if you’re looking for a specific value that starts with a specific letter follows with some numbers, and afterwards write it to “new value” under another element?

Is there anyway to search for this function?

Thanks in advance
Exting

Hi,

here’s one way. Note that for more consistent results you should use Regex, once you know the specific search requirements.
myXMLElem = xmlDoc.Root.Descendants.First(function(x) (x.Value.ToString.StartsWith(“A”) AndAlso x.Value.ToString.Contains(“123”)))

myOtherElem.Value = ,myXMLElem.Value

br,
Topi

Hi Topi

I solved it by using Regex after replacing unnecessary string, and afterwards serached for the specific letter follows with 4 numbers.

The last step would be giving a element/childitem a new value (overwriting), and change the fileformat from .xml to a specific fileextension.

Is there a easy way to perform this in UiPath?

Thanks in advance
Exting.

How to save the modified xml file. i am trying to use Invoke Method. But i am getting error message like “xdocument does not have public instance method name as Save”

You shouldn’t dig up 6 year old posts and reply to them. You should create a new post. Anyway, you’ll have to serialize the XML object into a string variable then use Write Text File.