I'm using Grails 2.5.6 and OpenJDK1.8.0.292.
I'm trying to download an XML file from a TFTP server, ammend one of the node values, and then write the ammended file locally. My code looks like :-
def xmlFile = simpleSftpService.downloadFile('tftp_file.xml')
def DeviceSettings = new XmlSlurper().parse(xmlFile)
println "Current IP Address = " + DeviceSettings.Network.IpAddress.text()
DeviceSettings.Network.IpAddress.value = "192.168.1.20"
def writer = new FileWriter('ammended_file.xml')
def builder = new StreamingMarkupBuilder()
writer << builder.bind {
mkp.yield DeviceSettings
}
This all runs through quite happily, and the output of println shows an IP address of 192.168.1.10, but the ammended_file.xml that is written also has a value of 192.168.1.10 for the IpAddress node, which is what it was originally set to in the tftp_file.xml, rather than the new value of 192.168.1.20
My XML file looks something like (I've left out all the rest of the XML which is, I think, irrelevant) :-
<DeviceSettings>
<Network>
<IpAddress>192.168.1.10</IpAddress>
</Network>
</DeviceSettings>
I'm certain I'm getting confused with how you can change or ammend a value in the XML so any pointers as to how I should do this would be greatfully received.