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)
Activity
Paul King
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Description |
The following gives an error:
{code} 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 ) {code} Gives the following error: {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} However if we change the println to: {code} println XmlUtil.serialize( (groovy.util.slurpersupport.GPathResult)gpr ) {code} We get the correct output: {code} <?xml version="1.0" encoding="UTF-8"?> <stuff ver="1.0"> <properties> <foo>bar</foo> </properties> </stuff> {code} Looks like Groovy is picking the wrong method somewhere... (though I can see how) |
The following gives an error:
{code} 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 ) {code} Gives the following error: {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} However if we change the println to: {code} println XmlUtil.serialize( (groovy.util.slurpersupport.GPathResult)gpr ) {code} We get the correct output: {code} <?xml version="1.0" encoding="UTF-8"?> <stuff ver="1.0"> <properties> <foo>bar</foo> </properties> </stuff> {code} Looks like Groovy is picking the wrong method somewhere... (though I can't see how) |
Roshan Dawrani
made changes -
| Assignee | Roshan Dawrani [ roshandawrani ] |
Roshan Dawrani
made changes -
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Fix Version/s | 1.8-beta-1 [ 16013 ] | |
| Fix Version/s | 1.7.4 [ 16563 ] | |
| Resolution | Fixed [ 1 ] |
Paul King
made changes -
| Status | Resolved [ 5 ] | Closed [ 6 ] |
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.