I have the codes below. Statement 1 loads an xml file of average size (~300-400KB) and stores the content into a string variable (xmlContent). Now the statement 2 will put the value of the jsp variable xmlContent to the javascript variable xmlText. The statement 3 will try to create an XMLDocument object in javascript (load string as xml document so that it can be parsed through DOM methods).
I must say that the xml file contains both single and double quotes inside it and also it contains entities like &***;
. Now why the third statment returns null? can somebody explain?
Can somebody tell me some better way to transfer the xml string data like by performing some encoding/decoding or by escaping ?
Thanks.
<%
String xmlContent = FileReader.readFile("/xml/books.xml");
%>
<script type="text/javascript">
var xmlText = ' <% =xmlContent %> ';
new DOMParser().parseFromString(xmlText, "text/xml");
//I know that it will not work in IE
</script>