Hi all,
I've encountered a strange issue with Groovy's (1.7.3) XmlUtil.serialize( GPathResult ) method. It throws a 'Content is not allowed in prolog' error when I call it with a GPathResult, but groovy.util.Node is serializing just fine. Here is the very simple Groovy Script I am trying:
import groovy.xml.XmlUtil
import groovy.xml.StreamingMarkupBuilder
def xmlStr = """<?xml version="1.0" encoding="UTF-8"?><stuff>ver="1.0"><properties><foo>bar</foo></properties></stuff>"""
//to pretty print GPathResult -- NOT WORKING
def gpr = new XmlSlurper().parseText( xmlStr )
println XmlUtil.serialize( gpr )
println 'trying groovy.util.Node'
//to pretty print groovy.util.Node -- WORKS
def node = new XmlParser().parseText( xmlStr )
println( XmlUtil.serialize( node ) )
This is the output I get:
[Fatal Error] :1:1: Content is not allowed in prolog.
ERROR: 'Content is not allowed in prolog.'
<?xml version="1.0" encoding="UTF-8"?>
trying groovy.util.Node
<?xml version="1.0" encoding="UTF-8"?>
<stuff ver="1.0">
<properties>
<foo>bar</foo>
</properties>
</stuff>
I am using Groovy Version: 1.7.3 JVM: 1.6.0_20 on Mac OS X Snow Leopard
Is anyone else experiencing this?