• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Xstream xml from toXML give problem to display in javscript

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yest it is working fine

thanks.
 
Do you want ants? Because that's how you get ants. And a tiny ads:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic