Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.7.3
-
Fix Version/s: 1.7.4, 1.8-beta-1
-
Component/s: groovy-jdk, XML Processing
-
Labels:None
-
Number of attachments :
Description
The following gives an error:
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>""" def gpr = new XmlSlurper().parseText( xmlStr ) println XmlUtil.serialize( gpr )
Gives the following error:
[Fatal Error] :1:1: Content is not allowed in prolog. ERROR: 'Content is not allowed in prolog.' <?xml version="1.0" encoding="UTF-8"?>
However if we change the println to:
println XmlUtil.serialize( (groovy.util.slurpersupport.GPathResult)gpr )
We get the correct output:
<?xml version="1.0" encoding="UTF-8"?> <stuff ver="1.0"> <properties> <foo>bar</foo> </properties> </stuff>
Looks like Groovy is picking the wrong method somewhere... (though I can't see how)
The issue is that groovy.util.slurpersupport.Node#writeTo(Writable) does not generate the String form of the nodes correctly.
Where it should generate
it generates
And then with the xml string going simply as "bar", it throws the "Content is not allowed in prolog." error correctly.