If you need the raw unencoded output, you can do:
chart.setXMLData('${raw(sinistralidadePSChartData)}');
Question
What's the best approach to print a xml string in Grails in this case:
Controller DashboardController.groovy:
package vs3
//import vs3.Navbar
class DashboardController {
def index() {
def sinistralidadePSChartData = new String()
sinistralidadePSChartData = '<chart labelStep="2" caption="Monthly Report" subCaption="Unique Visitors" yAxisName="Visitor Count" xAxisName="Date" showValues="0" showShadow="0" formatNumberScale="0" showLimits="0" canvasBorderAlpha="0" showBorder="0" divLineAlpha="30" anchorRadius="4" anchorBgColor="0377D0" anchorBorderColor="FFFFFF" anchorBorderThickness="1" anchorAlpha="90" showPlotBorder="1" plotBorderThickness="4" plotBorderColor="0377D0" plotFillColor="0377D0" plotGradientColor="" plotFillAlpha="20" bgColor="FFFFFF" showAlternateHGridColor="0" numVDivLines="2" toolTipBgColor ="DEF1FF" toolTipBorderColor ="2C516D"><set label="1 March 2014" value="490" /><set label="2 March 2014" value="510" /><set label="3 March 2014" value="1546" /><set label="4 March 2014" value="1250" /><set label="5 March 2014" value="1000" /><set label="6 March 2014" value="540" /><set label="7 March 2014" value="560" /><set label="8 March 2014" value="580" /><set label="9 March 2014" value="600" /><set label="10 March 2014" value="620" /><set label="11 March 2014" value="640" /><set label="12 March 2014" value="660" /><set label="13 March 2014" value="680" /><set label="14 March 2014" value="700" /></chart>'
render(view:'/templates/dashboard',model:[sinistralidadePSChartData:sinistralidadePSChartData])
}
}
View/Template:
<g:applyLayout name="page">
<h3>Dashboard</h3>
<script type="text/javascript" src="/vs3/FusionCharts_XT_Evaluation/Charts/FusionCharts.js"></script>
<div id="chartdiv" align="left">Chart will load here</div>
<script type="text/javascript">
var chart = new FusionCharts("Area2D", "ChartId","580", "400", "0", "0");
chart.setXMLData('${sinistralidadePSChartData}');
chart.render("chartdiv");
</script>
<g:link url="/vs3">Voltar</g:link>
</g:applyLayout>
But it simply can't print all the quotes and all I can have is a badly xml/string badly printed in my page like:
chart.setXMLData('<chart labelStep="2" caption="Monthly Report" subCaption="Unique Visitors" (...)
How can I handle this issue?
Solution
If you need the raw unencoded output, you can do:
chart.setXMLData('${raw(sinistralidadePSChartData)}');