Hi i am learning xml , in a very simple code i got an error saying
"Uncaught TypeError: Cannot call method 'getElementsByTagName' of null"
i am getting this in all browsers ,i have tried to look for solution on google but could not find ,Plz help
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><title>http request</title>
<head>
<link rel="shortcut icon" href="twitterfinalcut/twittericon.jpg" />
</head>
<body>
<script type="text/javascript">
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
var xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","note.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var x=xmlDoc.getElementsByTagName("CD");
document.write (x[0].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);
document.write (x[0].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
</script>
</body>
</html>
Here is the simple xml file "note.xml" code
<?xml version="1.0" encoding="ISO-8859-1"?>
<CATALOG>
<CD>
<ARTIST>Kenny Rogers</ARTIST>
<TITLE>For the good times</TITLE>
<COUNTRY>UK</COUNTRY>
<COMPANY>Mucik Master</COMPANY>
<PRICE>8.70</PRICE>
<YEAR>1995</YEAR>
</CD>>
</CATALOG>