I want to parse an XML file through JavaScript.
I wrote the following code, it works fine开发者_Python百科, but it displays only parsed values instead of the complete XML file.
function onDeviceReady()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","books.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
}
I also tried responseXML instead of responseText, but it didn't work.
Its cause the browser parse the xml and show only the value. Its the same as open a xml direct in the browser. You have to replace all <
with <
and >
with >
, before setting the string as innerHTML.
精彩评论