Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-31-2012, 04:52 PM   PM User | #1
learner guy
New Coder

 
Join Date: Jul 2011
Posts: 19
Thanks: 6
Thanked 0 Times in 0 Posts
learner guy is an unknown quantity at this point
Uncaught TypeError: Cannot call method 'getElementsByTagName' of null

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

Code:
<!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

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>
learner guy is offline   Reply With Quote
Old 01-31-2012, 08:28 PM   PM User | #2
Alex Vincent
Moderator


 
Join Date: May 2002
Location: Hayward, CA
Posts: 1,427
Thanks: 1
Thanked 19 Times in 17 Posts
Alex Vincent is on a distinguished road
xmlDoc would be null if the returned file was not well-formed XML. There's a couple ways this could happen:

1. The content-type header was not a valid XML content type (it might've been text/plain, for example)
2. The XML document was not well-formed.

The latter doesn't appear to be the case (though you do have </CD>>, that's not a well-formedness violation).
__________________
"The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
June 30, 2001
author, Verbosio prototype XML Editor
author, JavaScript Developer's Dictionary
https://alexvincent.us/blog
Alex Vincent is offline   Reply With Quote
Old 02-01-2012, 02:05 PM   PM User | #3
learner guy
New Coder

 
Join Date: Jul 2011
Posts: 19
Thanks: 6
Thanked 0 Times in 0 Posts
learner guy is an unknown quantity at this point
thanks for the reply , i have removed that typo of </CD>> but it is still not working
learner guy is offline   Reply With Quote
Old 02-01-2012, 02:56 PM   PM User | #4
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
I get the output "Kenny RogersFor the good times " and I don't get any error in FF.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Reply

Bookmarks

Tags
ajax, getelementsbytagname, xml

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:46 PM.


Advertisement
Log in to turn off these ads.