Tuesday, August 23, 2016

xml load in chrome

Please follow the following articles.

https://bugs.chromium.org/p/chromium/issues/detail?id=988#c9

https://productforums.google.com/forum/#!topic/chrome/hFCbU6MPw9k;context-place=topicsearchin/chrome/load$20xml$20file$20in$20chrome

Issue:

<html> 
<head> 
<script type="text/javascript"> 
function parseXML() 
{ 
try //Internet Explorer 
  { 
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); 
  } 
catch(e) 
  { 
  try //Firefox, Mozilla, Opera, etc. 
    { 
    xmlDoc=document.implementation.createDocument("","",null); 
    } 
  catch(e) 
    { 
    alert(e.message); 
    return; 
    } 
  } 
xmlDoc.async=false; 
xmlDoc.load("note.xml"); 

document.getElementById("to").innerHTML= 
xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue; 
document.getElementById("from").innerHTML= 
xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue; 
document.getElementById("message").innerHTML= 
xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue; 
} 
</script> 
</head> 

<body onload="parseXML()"> 
<h1>W3Schools Internal Note</h1> 
<p><b>To:</b> <span id="to"></span><br /> 
<b>From:</b> <span id="from"></span><br /> 
<b>Message:</b> <span id="message"></span> 
</p> 
</body> 
</html> 

and note.xml is: 
<?xml version="1.0" encoding="ISO-8859-1"?> 
<note> 
<to>Tove</to> 
<from>Jani</from> 
<heading>Reminder</heading> 
<body>Don't forget me this weekend!</body> 
</note> 



Try replacing:
var xmlDoc = document.implementation.createDocument("", " ", null);
xmlDoc.async = false;
xmlDoc.load(xmlsrc);

With:
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET", xmlsrc, false);
xmlhttp.send(null);
var xmlDoc = xmlhttp.responseXML.documentElement;

Courtesy of http://chromespot.com/showthread.php?t=1063.

Another blog https://bugs.chromium.org/p/chromium/issues/detail?id=988#c9  says

var error = "";
var file = root+"/inc/xml/linguas_"+lg+".xml";
try //Internet Explorer
{
 xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
 xmlDoc.async=false;
 xmlDoc.load(file);
}
catch(e)
{
 try //Firefox, Mozilla, Opera, etc.
 {
  xmlDoc=document.implementation.createDocument("","",null);
  xmlDoc.async=false;
  xmlDoc.load(file);
 }
 catch(e)
 {
  try //Google Chrome
  {
   var xmlhttp = new window.XMLHttpRequest();
   xmlhttp.open("GET",file,false);
   xmlhttp.send(null);
   xmlDoc = xmlhttp.responseXML.documentElement;
  }
  catch(e)
  {
   error=e.message;
  }
 }
}