Using getAttribute() in Firefox vs. IE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kreauchee
    New Member
    • Jan 2010
    • 6

    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.respons eXML;
    var manateeobj = xmlData.getElem entsByTagName(" 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
  • larztheloser
    New Member
    • Jan 2010
    • 86

    #2
    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 getElementsByTa gName. 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!)

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5390

      #3
      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

      Comment

      • Kreauchee
        New Member
        • Jan 2010
        • 6

        #4
        UPDATE: You both were right. I checked manatee.length and it was '1' on Firefox and '0' on IE. Problem was in getElementsByTa gName().

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

        Code:
        <?xml version="1.0" standalone="yes"?>
        <!DOCTYPE productdata [
        <!ENTITY bull "¥">
        <!ENTITY quot """>
        <!ENTITY amp "&">
        ]>
        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.
        Last edited by Kreauchee; Jan 15 '10, 10:20 PM. Reason: forgot CODE tags

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          depending on the XML you may run into problems when you want to validate the XML sometimes.

          Comment

          • Kreauchee
            New Member
            • Jan 2010
            • 6

            #6
            So this must be a solved problem. What is the best way for IE to getAttributesBy TagName() 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.

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              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.

              Comment

              Working...