Update XML File Data

I have a request to update XML file data. I need tp update following nodes,

TestNumber
TestEffectiveDate
TestExpirationDate

Glad some help on this.

1 Like

You need to write a Groovy code to do that. See the following

https://groovy-lang.org/processing-xml.html

1 Like

Hi Kazrayam,

Thanks for your reply. After updating the node with new value, trying to save using following code.
new XmlNodePrinter(new PrintWriter(new FileWriter(xmlFile))).print(xml)
When I open the file, it is fully blank file. Any idea?

Thanks

No. I have no idea.

It’s only you who can debug your code, as you haven’t disclosed your code at all.

It was my code that actually wasn’t updating the data properly caused the issue and now I am good it works fine! Thanks again your help. I really appreciated!

Thushar

Please post the fix on here, thanks!

It was mostly how I was accessing the node. Also I had formatting issues after I saved the content the xml file. Following article helped me to fully fix the code.

https://www.codementor.io/@nadbn/xml-parsing-using-groovy-1b3jr18h3c

1 Like