By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,934 Members | 1,538 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,934 IT Pros & Developers. It's quick & easy.

Using getAttribute() in Firefox vs. IE

P: 6
Hi,

So I'm somewhat baffled by this. I've looked online and found several solutions but none seem to be working for me.

I have an xml file like this:

<manatee num="6723-MT">
<stuff></stuff>
</manatee>

and javascript trying to get the 'num' like this:

var xmlData = xmlhttp.responseXML;
var manateeobj = xmlData.getElementsByTagName("manatee");
var id = manateeobj[0].getAttribute('num');

This works for me in every browser except IE which gives me the error "0" is null or not an object. I'm sure whatever I'm doing wrong is a simple oversight but I can't, for the life of me, figure out why it works in FF, Safari, Opera, Chrome, and even my android phone's default web browser but not in IE.

Any help would be appreciated.

-K
Jan 13 '10 #1
Share this Question
Share on Google+
6 Replies


P: 86
What bugs me about your problem is that if manateeobj.0. is not an element object I can't think what it would be unless manateeobj is not an array. So, I suspect that the "bad" code here is in getElementsByTagName. Which IE actually has supported since version 5. Therefore, I suspect that either this is a bug in IE itself, or you are breaching security restrictions by reading the XML file (although I can't think why microsoft would put security on reading XML files!)
Jan 13 '10 #2

gits
Expert Mod 5K+
P: 5,390
it might be that the first retrieved child is a whitspace or a textnode anyway ... since there seem to be linebreaks in the XML-file. so you might check the nodeType and/or loop through the child elements and stop at a found 'stuff'-node.

kind regards
Jan 14 '10 #3

P: 6
UPDATE: You both were right. I checked manatee.length and it was '1' on Firefox and '0' on IE. Problem was in getElementsByTagName().

Then I took a look at the xml file (which is generated by another person's perl scripts) and found it began with:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" standalone="yes"?>
  2. <!DOCTYPE productdata [
  3. <!ENTITY bull "">
  4. <!ENTITY quot """>
  5. <!ENTITY amp "&">
  6. ]>
There are tons of those !ENTITY tags in there and that must have been what was throwing IE off. I removed them and replaced it with:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

I don't know much about xml.....is this going to cause problems for us in the future when people try to store &'s and *'s in the xml?

Either way, thanks for your help, guys. I really appreciate it.
Jan 15 '10 #4

Dormilich
Expert Mod 5K+
P: 8,639
depending on the XML you may run into problems when you want to validate the XML sometimes.
Jan 15 '10 #5

P: 6
So this must be a solved problem. What is the best way for IE to getAttributesByTagName() in an xml file that has declared <!ENTITY> tags in it's DOCTYPE?

Firefox and every other browser seems to be able to handle it but it apparently freaks IE out.
Jan 15 '10 #6

Dormilich
Expert Mod 5K+
P: 8,639
it but it apparently freaks IE out.
as usual.

but I don’t think it matters, since I don’t expect JavaScript to validate XML.
Jan 15 '10 #7

Post your reply

Sign in to post your reply or Sign up for a free account.