| | |
Error reading XML file in Javascript
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2006
Posts: 5
Reputation:
Solved Threads: 0
Dear all
I have this xml file datechanged.xml:
- <changedate>
<date>04/02/2006</date>
</changedate>
In a Javascript file I have folowing code:
I have this xml file datechanged.xml:
- <changedate>
<date>04/02/2006</date>
</changedate>
In a Javascript file I have folowing code:
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") ;I alwas get this error:
xmlDoc.async="false" ;
xmlDoc.load("datechanged.xml") ;
xmlObj=xmlDoc.documentElement ;
sDate = xmlObj.childNodes(0).firstChild.text;
var chDate=new Date(sDate) ;
xmlObj is null or is not an object
Hi,
What you have works for me in IE7.0 - Which doesn't mean it will work in IE6, but I will presume it does and that you actually want it to work in Mozilla.
In which case, you need to use the XMLHttpRequest Object...
This doesn't work on my IE7.0 - But I'm assuming it won't matter much. I also consider this the cool way of loading XML data... I much less cool way of doing this is:
The second example works on both Firefox 1.0.5 and IE7.0
What you have works for me in IE7.0 - Which doesn't mean it will work in IE6, but I will presume it does and that you actually want it to work in Mozilla.
In which case, you need to use the XMLHttpRequest Object...
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var xmlDoc = null; if (window.XMLHttpRequest) { // Mozilla, Safari,... xmlDoc = new XMLHttpRequest(); if (xmlDoc.overrideMimeType) { xmlDoc.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { // IE try { xmlDoc = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlDoc = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } xmlDoc.onreadystatechange = function() { if(xmlDoc.readyState==4) { xmlObj = xmlDoc.responseXML.getElementsByTagName('changedate').item(0); var sDate = xmlObj.getElementsByTagName('date').item(0).firstChild.data; var chDate=new Date(sDate); alert(chDate); } } xmlDoc.open("GET", "datechanged.xml", true); xmlDoc.send(null);
This doesn't work on my IE7.0 - But I'm assuming it won't matter much. I also consider this the cool way of loading XML data... I much less cool way of doing this is:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var xmlDoc function loadXML() { //Code for IE if (window.ActiveXObject) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load("datechanged.xml"); getmessage() } //Code for Mozilla else if (document.implementation && document.implementation.createDocument) { xmlDoc=document.implementation.createDocument("","",null); xmlDoc.load("datechanged.xml"); xmlDoc.onload=getmessage } else { alert('Your browser cannot handle this script'); } } function getmessage() { alert(xmlDoc.getElementsByTagName('changedate').item(0).getElementsByTagName('date').item(0).firstChild.data); } loadXML();
The second example works on both Firefox 1.0.5 and IE7.0
![]() |
Similar Threads
- Multiple Table Reading From An Xml File (VB.NET)
- problem reading xml file in c# (C#)
- Error reading zip (PHP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Call a external js function into another js function
- Next Thread: Explorer Blocking Script
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug calendar captchaformproblem checkbox child close column createrange() css cursor decimal dependent design disablefirebug dom download dropdown editor element embed engine error events explorer ext file form forms google gwt gxt hiddenvalue highlightedword hint html htmlform ie8 iframe images index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jump libcurl listbox math media microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php player post problem progressbar regex runtime scroll search security select shopping size software sql text textarea unicode w3c web website window windowofwords windowsxp wysiwyg \n





