I am unable to delete the sub child xml Nodes. Here is the input and code am trying with
import groovy.xml.*; def employees='''<Employees> <Employee> <ID>123</ID> <Name>xyz</Name> <Addresses> <Address> <Country>USA</Country> <ZipCode>40640</ZipCode> </Address> </Addresses> </Employee> <Employee> <ID>345</ID> <Name>abc</Name> <Addresses> <Address> <Country>CA</Country> <ZipCode>50640</ZipCode> </Address> </Addresses> </Employee> </Employees>''' def fields = ['Name','ZipCode'] def xml = new XmlParser().parseText(employees) xml.Employee.each { node -> node.children().reverse().each{ if(!fields.contains(it.name())) { node.remove(it) } } } XmlUtil.serialize(xml) How to delete the node ZipCode from the xml? -- View this message in context: http://groovy.329449.n5.nabble.com/Delete-Sub-Child-XML-Nodes-tp5734792.html Sent from the Groovy Dev mailing list archive at Nabble.com.