How do I quickly print a groovy.util.slurpersupport.Node?

Nicolenerdy

New Member
Is there an easy way to convert a \[code\]groovy.util.slurpersupport.Node\[/code\] to a \[code\]groovy.util.Node\[/code\]?I am trying to use the \[code\]XmlNodePrinter\[/code\] on a node coming from an \[code\]XmlSlurper\[/code\], for some quick debugging. Here is my code (probably not the most elegant):\[code\]def xml = new XmlSlurper().parse( new File( path + pomFile ) )def services = xml.build.plugins.plugin.configuration.servicesservices.children().findAll{ it.artifactId.text() == serviceName }.each { config -> // begin section to dump "config" for debugging def stringWriter = new StringWriter() new XmlNodePrinter(new PrintWriter(stringWriter)).print(config[0]) println stringWriter.toString() // end section to dump "config" for debugging // do some other processing on the config node}\[/code\]This throws the following on the \[code\]config[0]\[/code\] line:\[code\]org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'groovy.util.slurpersupport.Node@14712c3' with class 'groovy.util.slurpersupport.Node' to class 'groovy.util.Node'\[/code\]How can I quickly print out the xml representation of \[code\]config\[/code\]?I am limited to Groovy 1.7.0.-EDIT: I also tried the following but receive an error:\[code\]services.children().findAll{ it.artifactId.text() == serviceName }.each { config -> println XmlUtil.serialize(config)\[/code\]Here's what's printed:\[code\][Fatal Error] :1:1: Content is not allowed in prolog.ERROR: 'Content is not allowed in prolog.'<?xml version="1.0" encoding="UTF-8"?>\[/code\]
 
Back
Top