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…
& 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
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?
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”)))
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.