tag:blogger.com,1999:blog-7966819206399566415.post5290392447726140074..comments2023-10-30T08:57:25.093-07:00Comments on John's Blog: Pretty Printing Groovy's StreamingMarkupBuilderjohnrellishttp://www.blogger.com/profile/13318765113024624030noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-7966819206399566415.post-68825327553631022122014-05-30T11:24:31.623-07:002014-05-30T11:24:31.623-07:00Same indentation issue for me as well. I thought G...Same indentation issue for me as well. I thought Groovy would simplify my life, but it seems to not alleviate the requirement for increasing third party dependencies in Java. I have a lot of trouble each time I need to add some dependency, because I am using Maven and often need to Google long times to get a working set of Maven coordinates for each new package needed. And why are more and more links on forums and web pages NON-CLICKABLE? This is a real pain. Firefox issue?Anonymoushttps://www.blogger.com/profile/12618757976607978115noreply@blogger.comtag:blogger.com,1999:blog-7966819206399566415.post-64335358673006719042010-11-03T02:25:59.506-07:002010-11-03T02:25:59.506-07:00Hey,
http://groovyconsole.appspot.com/script/3140...Hey,<br /><br />http://groovyconsole.appspot.com/script/314001<br /><br />Seems to work, this is using 1.8 though.<br /><br />I have tried using 1.7.4 and 1.7.5 and it also seems to work. If you are having issues with you should submit a jira with a failing test or try the user list but everything seems to be working fine!<br /><br />Good luck!johnrellishttps://www.blogger.com/profile/13318765113024624030noreply@blogger.comtag:blogger.com,1999:blog-7966819206399566415.post-65358574751834820602010-11-03T00:15:03.325-07:002010-11-03T00:15:03.325-07:00Actually the XmlUtil.serialize just puts a line fe...Actually the XmlUtil.serialize just puts a line feed and carriage return... so im getting an XML with no indentation... I don't see a way to do this really pretty...<br /><br />Here is some example code:<br /><br />def xmlBuilder = new StreamingMarkupBuilder().bind() { mkp.xmlDeclaration(version:'1.0')<br /> ROOT(stage:xmlExportHelper.getStageString()) {<br /> LANGUAGE(publicationEntity.getLanguage().getName())<br /> ENTRY() {<br />...<br /><br />return XmlUtil.serialize(xmlBuilder.toString())<br /><br /><br /><br />Using Groovy 1.7.5Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7966819206399566415.post-48432303043443218842009-08-07T04:45:57.847-07:002009-08-07T04:45:57.847-07:00Nice one Paul, thanks!Nice one Paul, thanks!johnrellishttps://www.blogger.com/profile/13318765113024624030noreply@blogger.comtag:blogger.com,1999:blog-7966819206399566415.post-6683992206724738272009-08-06T22:12:49.692-07:002009-08-06T22:12:49.692-07:00Or this slight variation:
import groovy.xml.*
de...Or this slight variation:<br /><br />import groovy.xml.*<br /><br />def personList = {<br /> people {<br /> person(id: 1) {<br /> firstName("John")<br /> lastName("Doe")<br /> data_labels {<br /> unescaped << "<![CDATA[hello]]>"<br /> }<br /> }<br /> }<br />}<br />def xml = new StreamingMarkupBuilder()<br />println XmlUtil.serialize(xml.bind(personList))Paul Kingnoreply@blogger.comtag:blogger.com,1999:blog-7966819206399566415.post-76770019235475897482009-08-06T22:08:17.507-07:002009-08-06T22:08:17.507-07:00Nice example. You can also use XmlUtil.serialize a...Nice example. You can also use XmlUtil.serialize as shown below:<br /><br />import groovy.xml.*<br /><br />String cData = "<![CDATA[hello]]>"<br />def xml = new StreamingMarkupBuilder()<br />def personList = {<br /> people {<br /> person(id: 1) {<br /> firstName("John")<br /> lastName("Doe")<br /> data_labels {<br /> mkp.yieldUnescaped(cData)<br /> }<br /> }<br /> }<br />}<br />println XmlUtil.serialize(xml.bind(personList))Paul Kingnoreply@blogger.com