views:

158

answers:

1

I've got a Servlet that generates a XML string (relatively long) which I then pass to a Javascript variable in the forwarded JSP file:

$(document).ready(function() {
    ...
    var itXML = <% out.print((String) request.getAttribute("xml")); %>;
    ...
}

This seems to work just fine in Firefox, but when I run the same project on IE8 I get a syntax error for this line.

Any Ideas?

+2  A: 

Internet Explorer doesn't support E4X, use JSON instead of XML.

David Dorward
+1 Boom - straight to the point!!!
David Relihan
And to generate the JSON string, I can recommend [Google Gson](http://code.google.com/p/google-gson/).
BalusC
I wansn't aware I was using E4X...As all of my supporing javascript code assumes the variable is xml, any idea how I can easily convert the json back into xml in the client? In fact, I'd be happy to get a good link or small code sample to show me how to convert the string to json on the servlet and then convert it back to XML on the client.Thanks!
Ronen
The link above includes mention of Java libraries near the bottom. There isn't an easy way to convert back to XML. AFAIK, getting an XML object from a string in browsers isn't something that is trivial to do in a cross browser compatible fashion anyway. Also, having a JS object is likely to give better performance.
David Dorward
Well, I guess it's back to the code... Thanks for the help!
Ronen