0

ANSWERED: removing the header info from the XML file solved the issue. IE is great!

The following code works in Firefox and Chrome, not in IE.

I get the error

SCRIPT5007: Unable to get value of the property 'childNodes': object is null or undefined.  
line 106, character 3`

Line 106 is the first line inside the sort function, the one that begins 'var aCat = a.getElementsByTagName'....

None of the nodes being sorted are empty, although within the same in the xml file, there are some blank nodes (ie im sorting on , none of which are empty, but some people don't have phone number, or beeper numbers, etc. so some of those are empty)

When I tried putting the sort in a try-catch block IE just didn't read any of the nodes, they all threw an exception. (again, Chrome and Firefox worked with the try-catch block)

I'm stumped, any ideas?

function populateSection(listType, tableID ) {

if (window.XMLHttpRequest) {/*code for IE7+, Firefox, Chrome, Opera, Safari*/ xmlhttp=new XMLHttpRequest(); }
else {/* code for IE6, IE5*/ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }

var table = tableID;
var list = listType;

xmlhttp.open("GET",'contactlist.xml',false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

var xmlGet = xmlDoc.getElementsByTagName("PERSON");
var x = Array.prototype.slice.call(xmlGet,0);

x.sort(function(a,b) {
    var aCat = a.getElementsByTagName("LASTNAME")[0].childNodes[0].nodeValue;
    var bCat = b.getElementsByTagName("LASTNAME")[0].childNodes[0].nodeValue;
    if (aCat > bCat) return 1;
    if (aCat < bCat) return -1;
    return 0;
});

//then cycle through the array, adding table rows for each node
...}

EDIT: Here's a portion of the xml file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CONTACTLIST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <PERSON>
        <LASTNAME>ALLEN</LASTNAME>
        <FIRSTNAME>Korrie</FIRSTNAME>
        <EMAIL>redacted@evms.edu</EMAIL>
        <PHONE>123456</PHONE>
        <LIST>main</LIST>
    </PERSON>
    <PERSON>
        <LASTNAME>BUESCHER</LASTNAME>
        <FIRSTNAME>Chris</FIRSTNAME>
        <EMAIL>redacted</EMAIL>
        <LIST>main</LIST>
    </PERSON>
    <PERSON>
        <LASTNAME>BUESCHER</LASTNAME>
        <FIRSTNAME>Steve</FIRSTNAME>
        <EMAIL>redacted@evms.edu</EMAIL>
        <PHONE>123456</PHONE>
        <LIST>main</LIST>
        <LABOTHER>123456</LABOTHER>
        <BEEPER>123456</BEEPER>
    </PERSON>
    <PERSON>
        <LASTNAME>CHARTERS</LASTNAME>
        <FIRSTNAME>Michelle</FIRSTNAME>
        <EMAIL>redacted@evms.edu</EMAIL>
        <PHONE>123456</PHONE>
        <LIST>main</LIST>
    </PERSON>
quothmarc
  • 17
  • 1
  • 4
  • The error seems to tell you what is wrong: `object is null or undefined`. Try adding a check that the object exists (and is not null) before working with it. – David Starkey Aug 16 '13 at 16:04
  • 1
    Why are you doing this the hard way instead of using something like jQuery? – j08691 Aug 16 '13 at 16:04
  • Show us your xml file please. IE is known for not parsing everything exactly. – Bergi Aug 16 '13 at 16:23
  • IE9. This is for work so that's non-negotiable. And I do have a meta tag forcing IE9 rendering. Added a portion of the xml file. – quothmarc Aug 16 '13 at 16:26

1 Answers1

0

Since we aren't shown your XML, we're going to have a hard time figuring out where the code is breaking, but here are some guesses:

var x = Array.prototype.slice.call(xmlGet,0); This doesn't work in IE8, and may be buggy in IE9. Try alert(x) and see if the object is null.

If your XML starts with <?xml version="1.0" encoding="utf-8" ?> or similar, this can actual break in IE. I don't know why. Try removing it and seeing if it works.

MattDiamant
  • 8,010
  • 4
  • 35
  • 45
  • Removing that header info in the XML file didn't fix it. When I `alert(x)` after the slice statement the object is not null in Chrome and FF. In IE I get an error `Object doesn't support this property or method` – quothmarc Aug 16 '13 at 16:38
  • Scratch that, removing the header info did work. Which is a pain, because Excel adds it back every time it's saved so now I have to show the admin assistant how to edit the xml file directly, instead of doing it in Excel. – quothmarc Aug 16 '13 at 16:57