1

My xml is like this:

<rootnode>
   <child name="tony">
   ...
   </child>
   <child name="antho">
   ...
   </child>
</rootnode>

I want to be able to output the xml element for child tony verbatim. I can find this element using XmlSlurper but then I am left with an object represent, I just want the XML verbatim. How do I do that?

   <child name="tony">
   ...
   </child>
More Than Five
  • 9,959
  • 21
  • 77
  • 127

1 Answers1

1

Check the answer to this question: Load, modify, and write an XML document in Groovy

In short, it seems the simple solution is to read xml with XmlSlurper and write with XmlUtil:

def xml = new XmlSlurper().parse(xmlString)
def prettyXmlNode = XmlUtil.serialize(xml)
CommodoreBeard
  • 340
  • 2
  • 12