JavaScript: ActiveXObject MSXML2.XMLHTTP is not returning XML on succesful loads...? -


i trying write internet explorer 8 solution loading xml through 'file' protocol, since site building intended sent packages directly users. have experienced in attempting use xmlhttprequest handle seems support i've read online: ie8's xmlhttprequest implementation dislikes protocol, have use activexobject handle loading.

i have experimented various people's suggestions, , have code appears obtaining file, responsetext field filled contents of file. however, responsexml.xml field supposed hold xml (or text representation of it, none of documentation i've read has been clear) empty string. how can configure activexobject load xml properly?

as bonus, explain how supposed use loaded xml once loading successfully? have yet find documents explain bit.

here javascript:

function isie() {     return navigator.useragent.lastindexof('trident') > 0; }  // block ensures xml request occurs in same domain. var path = document.location.href; path = path.substr(0, path.lastindexof('/') + 1);  if (isie() && location.protocol == 'file:') {     var xmlrequest = new activexobject('msxml2.xmlhttp');     xmlrequest.open('get', path + 'xml/shared.xml', false);     xmlrequest.onreadystatechange = usexml;     xmlrequest.send();      function usexml() {         if (xmlrequest && xmlrequest.readystate && xmlrequest.readystate == 4) {             alert(xmlrequest.responsetext);    // displays file             alert(xmlrequest.responsexml.xml); // displays nothing         }     } } 

and here xml file:

<?xml version="1.0" encoding="iso-8859-1"?> <shared>     <page_title>         test page title     </page_title> </shared> 

i used w3schools xml validator check whether file somehow malformed. not.

this because local file not served text/xml (as server do) , ie not parse it..

you can parse manually microsoft.xmldom object

function usexml() {         if (xmlrequest && xmlrequest.readystate && xmlrequest.readystate == 4) {             alert(xmlrequest.responsetext);    // displays file             xmldoc=new activexobject("microsoft.xmldom");             xmldoc.async="false";             xmldoc.loadxml(xmlrequest.responsetext);             title = xmldoc.documentelement.getelementsbytagname('page_title')[0];             alert(title.childnodes[0].nodevalue);         }     } 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -