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>
4

1 回答 1

0

由于我们没有看到您的 XML,我们将很难确定代码在哪里中断,但这里有一些猜测:

var x = Array.prototype.slice.call(xmlGet,0); 这在 IE8 中不起作用,并且在 IE9 中可能有问题。试试看alert(x)对象是不是null

如果您的 XML 以<?xml version="1.0" encoding="utf-8" ?>或类似开头,这可能会在 IE 中实际中断。我不知道为什么。尝试删除它并查看它是否有效。

于 2013-08-16T16:35:03.670 回答