• Post Reply Bookmark Topic Watch Topic
  • New Topic

Xstream xml from toXML give problem to display in javscript  RSS feed

 
G.Sathish kumar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using Xstream i need to create the following xml file but i created with toXML method which is availble in the Xstream and my problem is i need to pass this string object to one javascript function to load the chart


<Chart caption="Model Comparison" shownames="1" showvalues="0" decimals="0" numberPrefix="$">
<categories>
<category label="Lot Quantity"/>
<category label="Total Cost"/>
</categories>
<dataset seriesName="Lot Quantity" color="8BBA00" showValues="0">
<set>
<set value="100"/>
<set value="101"/>
<set value="102"/>
</set>
</dataset>
<dataset seriesName="Total Cost" color="8BBA00" showValues="0">
<set>
<set value="1000"/>
<set value="1001"/>
<set value="1002"/>
</set>
</dataset>




so when i am passing am getting the error and the view source is

<script type='text/javascript'>
var chart_Compare Model = new FusionCharts('../content/charts/MSColumn3D.swf', 'Compare Model', '650', '300', '0', '0');
//Provide entire XML data using dataXML method
chart_Compare Model.setDataXML("<Chart caption=\"Total Cost\"><categories>
<category label="Lot Quantity"/>
<category/>
</categories>
<dataset seriesName="Lot Quantity">
<set>
<set value="100"/>
<set value="101"/>
<set value="102"/>
</set>
</dataset>
<dataset seriesName="Total Cost">
<set>
<set value="100"/>
<set value="101"/>
<set value="102"/>
</set></dataset><set/></Chart>");
//Finally, render the chart.
chart_Compare Model.render("Compare ModelDiv");
</script>

</Chart>


the problem is toXml from xstream returned xml as string but the string contains the xml nodes line by line so when i pass it to javascript the line is brokened could any one please give the help?
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Replace \n with \\n before printing it to the web page. Line breaks will show up as \n literals, which are then treated as line breaks by JavaScript. Or you can replace \n with the empty string stripping out all enters completely.

On a side note, your approach is still a bit dangerous - if your XML document contains any quotes (') that will end the JavaScript string containing the XML document.
 
G.Sathish kumar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yest it is working fine

thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!