head 1.1; access; symbols; locks ingo:1.1; strict; comment @# @; 1.1 date 2007.05.02.18.58.00; author ingo; state Exp; branches; next ; desc @@ 1.1 log @Initial revision @ text @function importXML(filename, callback) { var xmlDoc; if (document.implementation && document.implementation.createDocument) { xmlDoc = document.implementation.createDocument("", "", null); xmlDoc.onload = callback; } else if (window.ActiveXObject) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.onreadystatechange = function () { if (xmlDoc.readyState == 4) callback() }; } else { alert('Your browser can\'t handle this script'); return; } xmlDoc.load(filename); return xmlDoc; } function test(data) { // taking care of data } function handler() { if(this.readyState == 4 && this.status == 200) { // so far so good if(this.responseXML != null && this.responseXML.getElementById('test').firstChild.data) // success! test(this.responseXML.getElementById('test').firstChild.data); else test(null); } else if (this.readyState == 4 && this.status != 200) { // fetched the wrong page or network error... test(null); } } var client = new XMLHttpRequest(); client.onreadystatechange = handler; client.open("GET", "test.xml"); client.send(); function a_message() { data = importXML("test.xml", document_loaded) } function document_loaded() { document.write('data loaded: ' + data); var x = xmlDoc.getElementsByTagName('emperor'); for(i=0; i < x.length; ++i) { document.write(i); document.write(x[i]); } } // EOF // @