How to open edit a tag value and save xml in katalon

Hi,

I have a requirement
Open the Xml file
Navigate to the price tag
Update the price value
Save the xml
Please provide the code if anybody worked before
Thank you

it’s easy:

Thank U .
It worked as said in the above stack overflow forum.
But the format is changed.
The tags are broken in two lines and saved.
T need the correct format for the tags.

if you need any further help, we need more details of problem

Thank You for your reply.
I found the correct code for the above problem.
It save the xml with same format as before.

def xmlFile = “C:\MLFile.xml”
def xml = new XmlParser().parse(xmlFile)

//Path of the tag “price” which need to be updated to 17.420

xml.item_master.selling_price[0].price.any()
{
it.value = “170.420”
}
//Saves the xml in same format after editing
nodePrinter =new XmlNodePrinter(new PrintWriter(new FileWriter(xmlFile)))
nodePrinter.preserveWhitespace = true
nodePrinter.print(xml)

It works good!!! :grinning:

1 Like