开发者

return whole XML file instead of only the parsed value through JavaScript?

开发者 https://www.devze.com 2023-03-29 10:03 出处:网络
Iwant 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.

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 &lt; and > with &gt;, before setting the string as innerHTML.

0

精彩评论

暂无评论...
验证码 换一张
取 消