[groovy-user] Encoding issue with groovy.xml.XmlUtil.serialize()

282 views
Skip to first unread message

citron

unread,
Dec 1, 2011, 7:27:23 AM12/1/11
to us...@groovy.codehaus.org
Hi,

Any ideas why the serialized xml becomes empty in this case?

I think it should be possible to put an 'ü' charter in the xml element.

Thanks!


def xml ="""<?xml version="1.0" encoding="UTF-8"?>
<Schlüssel>
text content
</Schlüssel>"""

groovy.util.slurpersupport.GPathResult s = new XmlSlurper().parseText(xml)

println groovy.xml.XmlUtil.serialize(s) // results in empty xml, why?

----- OUTPUT
<?xml version="1.0" encoding="UTF-8"?>


-----
Project pages
AndersTool
earBuddy

--
View this message in context: http://groovy.329449.n5.nabble.com/Encoding-issue-with-groovy-xml-XmlUtil-serialize-tp5038513p5038513.html
Sent from the groovy - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Tim Yates

unread,
Dec 1, 2011, 7:52:48 AM12/1/11
to us...@groovy.codehaus.org
Had a quick look, and I believe that asString( GPathResult ) inside XmlUtil doesn't set the encoding property on the builder after it is constructed...

As a workaround, you can do:

def outxml = new groovy.xml.StreamingMarkupBuilder().with {
  encoding = 'UTF-8'
  '<?xml version="1.0" encoding="UTF-8"?>\n' + bindNode( s )
}
println outxml

Can you add this to the JIRA though, as it looks like a bug

Tim

citron

unread,
Dec 1, 2011, 6:43:32 PM12/1/11
to us...@groovy.codehaus.org
Thanks Tim!

Your suggestion is working and I added this to Jira.

http://jira.codehaus.org/browse/GROOVY-5158
http://jira.codehaus.org/browse/GROOVY-5158

-----
Project pages
AndersTool
earBuddy

--
View this message in context: http://groovy.329449.n5.nabble.com/Encoding-issue-with-groovy-xml-XmlUtil-serialize-tp5038513p5040216.html

Reply all
Reply to author
Forward
0 new messages