Hi thanks for the respons
however I am sorry, i am now completely confused :((
a. the default xml file gets loaded ONLY in FF (safari, chrome and opera do not load it …)
b. the variable ‘filename’ is detected correctly (thanks for indicating the ‘li’ element usage as opposed to the ‘a’ element) BUT
c. the LoadAgain function gets up to the alert ("the file " + filename + " has been loaded "); part and then
d. does not do anything (does not load the title and header)
here is how my code is currently:
External Javascript file:
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp.open(“GET”,dname,false);
xmlhttp.send(“”);
xmlDoc=xmlhttp.responseXML;
}
function get_set_Data () {
var title=xmlDoc.getElementsByTagName(“title”)[0].childNodes[0].nodeValue;
var author=xmlDoc.getElementsByTagName(“author”)[0].childNodes[0].nodeValue;
//geting the specific nodes values
document.getElementById(“header”).getElementsByTagName(‘h1’)[0].innerHTML= title;
document.getElementById(“header”).getElementsByTagName(‘h6’)[0].innerHTML= author;
//setting the specific nodes values in HTML elements
//there are few more functions in the JS file that are irrelevant for the purpose of this exercise
HTML FILE and more in-html JAVASCRIPT
<script type=“text/javascript”>
window.onload=function(){
loadXMLDoc(“papers.xml”); //this loads the default XML file i.e. paper1
get_set_Data();
scan();
scanForXML();
highlite();
}
function LoadAgain(filename){
var xml = loadXMLDoc(filename);
alert ("the file " + filename + " has been loaded ");
alert(xml.getElementsByTagName(“title”)[0].childNodes[0].nodeValue); //copied from above for testing - does not work
return false;
}
function scanForXML(){
var extLinks=document.getElementById(‘results_list’).getElementsByTagName(‘li’);
for (i=0; i<extLinks.length; i++) {
extLinks[i].onclick=function()
{
LoadAgain(this.id);
return false;
alert(this.id);
}
}
}
</script>
and then the pure HTML part (some of it):
HTML
<div id=“header”>
<h1> title </h1>
<h6> author </h6>
</div>
<div id=“text_content”>
<h4>Search Results</h4>
<ol id=“results_list”>
<li id=“paper2.xml”>
<a class=“tooltip” href=“paper2.xml”>Teaching with Tablet PC’s </a>
</li>
<li id=“paper3.xml”>
<a href=“paper3.xml” class=“tooltip”>Tablet PC’s as Instructional Tools </a>
</li>
<li id=“paper4.xml”>
<a href=“#” class=“tooltip”>Improving learning via CS1 </a></li>
</ol>
</div>
Samples from 3 different XML files:
papers.xml
<?xml version=“1.0” encoding=“ISO-8859-1”?>
<CATALOG>
<paper>
<title>TEACHING WITH TABLET PC’S</title>
<author>Kenrick Mock [ 2004 ]</author>
</paper>
</CATALOG>
paper2.xml
<?xml version=“1.0” encoding=“ISO-8859-1”?>
<CATALOG>
<paper>
<title>Tablet PC’s as Instructional Tools or the Pen is Mightier than the Board!</title>
<author>Cheryl L. Willis</author>
</paper>
</CATALOG>
paper3.xml
<?xml version=“1.0” encoding=“ISO-8859-1”?>
<CATALOG>
<paper>
<title>Learning in CS1 via Tablet-PC-based In-Class Assessment</title>
<author>Kimberle Koile</author>
</paper>
</CATALOG>