I have the following XML
<test>
<one>
<one1>120</one1>
<one2>115</one2>
</one>
<two>
<two1>100</two1>
<two2>50</two2>
</two>
I need to change the values to the following
<test>
<one>
<one1>121</one1>
<one2>116</one2>
</one>
<two>
<two1>101</two1>
<two2>51</two2>
</two>
My XML is stored locally. I have written the following groovy code to modify the XML
def xmlFile = "D:/Service/something.xml"
def xml = new XmlParser().parse(xmlFile)
xml.one[0].one1[0].each {
it.value = "201"
}
xml.one[0].one2[0].each {
it.value = "116"
}
xml.two[0].two1[0].each {
it.value = "101"
}
xml.two[0].two2[0].each {
it.value = "51"
}
new XmlNodePrinter(new PrintWriter(new FileWriter(xmlFile))).print(xml)
But i am getting this error
Caused by: groovy.lang.ReadOnlyPropertyException: Cannot set readonly property: value for class: java.lang.String
What am i doing wrong?