How do I insert the xml file data into a variable?

TheCrow

New Member
I am quite new to javascript and xml.I am trying to load an external xml file that can be changed with an event handler (onClick).The xml file loads ok. The problem is that I cannot retrieve the xml data. Variable xmlDoc appears always as null.What I am doing wrong? Also can you recommend any really good online courses for javascript, xml and php education? Need to get trained quickly and well.ThanksMy code below:External js file:\[code\]var xmlhttp;function GetXmlHttpObject() {if(window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safarireturn new XMLHttpRequest();}if (window.ActiveXObject){// code for IE6, IE5return new ActiveXObject("Microsoft.XMLHTTP");}return null;}function loadXMLDoc(url){xmlhttp=GetXmlHttpObject();if (xmlhttp==null){alert ("Your browser does not support XMLHTTP!");return;}xmlhttp.open("GET",url,true);alert (url);xmlhttp.send();xmlDoc=xmlhttp.responseXML;}function get_set_Data () { var title=xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;document.getElementById("header").getElementsByTagName('h1')[0].innerHTML= title;}\[/code\]HTML part:(page needs to load with a default xml file)\[code\]<body onLoad="loadXMLDoc('papers.xml'); get_set_Data();"> <button onClick="loadXMLDoc('papers.xml')">paper 1</button><button onClick="loadXMLDoc('paper2.xml')">paper 2</button><div id="header"> <h1> sample title </h1> <h6> </h6></div>\[/code\]
 
Back
Top