473,320 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Using getAttribute() in Firefox vs. IE

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
6 3178
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
5,390 Expert Mod 4TB
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
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
8,658 Expert Mod 8TB
depending on the XML you may run into problems when you want to validate the XML sometimes.
Jan 15 '10 #5
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
8,658 Expert Mod 8TB
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

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

Similar topics

2
by: CES | last post by:
All, I'm 2 for 2 on stupid questions this works in FireFox but not in IE it's not returning the value of the style element and I'm getting error?? document.getElementById('test').innerHTML =...
13
by: Noa | last post by:
Hi I have a page that looks like that: <form name="kuku1" action ="anotherpage.html" > <input name="name"> <input name="kuku2"> </form> As far as i know, "getAttribute" should return a...
2
by: emma.sax | last post by:
Hi I have the following code which is working in Firefox: function showOptions() { if(!document.getElementById) return false; if(!document.getElementsByTagName) return false; var lnks =...
6
by: vivekian | last post by:
Hi , In one of the javascript functions , i need to get the ids of the elements. This function works in Internet Explorer : var TabNames = ParentTab.childNodes ; for ( i = 0 ; i <...
4
by: mynameistechno | last post by:
I need to execute code in an onload event. e.g. eval(element.getAttribute('onload')); This works in Firefox but not in IE (surprise!). IE's getAttribute for the onload event seems to return an...
4
by: ICPooreMan | last post by:
I've got some code which works in firefox that's giving me fits in IE7 (maybe other versions too I haven't tested it). What I want to do is get the oncontextmenu attribute of something, change the...
7
by: petethebloke | last post by:
Can anyone help? I have a client who has made a "dynamic interactive map" of our city using Dreamweaver. Each map file has hotspots that pop-up a div with a little image when the mouse goes over...
3
by: jphaycock | last post by:
Hi all I am trying to get a url attribute from an xml node: <item> <media url="http://blablabla.com" /> </item> I can do this in IE with the following code: var newDom =...
12
by: prashant | last post by:
hi, i am trying to create an xml tag ref to hold link.php?id=1; or link.php?id=2 and so on. I want the links for all the fields(id) in the databse so that when i call them in my html page for...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.