を に変換する簡単な方法はありgroovy.util.slurpersupport.Node
ますgroovy.util.Node
か?
簡単なデバッグのために、XmlNodePrinter
からのノードでを使用しようとしています。XmlSlurper
これが私のコードです(おそらく最もエレガントではありません):
def xml = new XmlSlurper().parse( new File( path + pomFile ) )
def services = xml.build.plugins.plugin.configuration.services
services.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
}
config[0]
これにより、次の行がスローされます。
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'
のxml表現をすばやく印刷するにはどうすればよいconfig
ですか?
Groovy 1.7.0 に制限されています。
-
編集:次のことも試しましたが、エラーが発生しました:
services.children().findAll{ it.artifactId.text() == serviceName }.each { config ->
println XmlUtil.serialize(config)
印刷されたものは次のとおりです。
[Fatal Error] :1:1: Content is not allowed in prolog.
ERROR: 'Content is not allowed in prolog.'
<?xml version="1.0" encoding="UTF-8"?>