I've an issue with IE9 with the following code:
var XMLDocument = data;
var erreurs = new Array();
var test = data.lastChild.lastChild.childNodes;
for(var i=0; i<test.length; i++)
{
//var testx = test[i].textContent;
//alert("Test"+i+" = "+testx);
var testx = getText(test[i]);
alert(testx);
erreurs[i] = testx;
}
function getText(el) {
return el.textContent || el.innerText || el.nodeValue || '';
}
In FF, Opera and Safari, this code works fine.
In IE, it gives me:
Test0 = undefined
Test1 = undefined
My XML:
<error>
<missing>1</missing>
<missing>2</missing>
<missing>a</missing>
</error>
I just want to return the values of the nodes "missing".
Thank you very much for your help.
I've an issue with IE9 with the following code:
var XMLDocument = data;
var erreurs = new Array();
var test = data.lastChild.lastChild.childNodes;
for(var i=0; i<test.length; i++)
{
//var testx = test[i].textContent;
//alert("Test"+i+" = "+testx);
var testx = getText(test[i]);
alert(testx);
erreurs[i] = testx;
}
function getText(el) {
return el.textContent || el.innerText || el.nodeValue || '';
}
In FF, Opera and Safari, this code works fine.
In IE, it gives me:
Test0 = undefined
Test1 = undefined
My XML:
<error>
<missing>1</missing>
<missing>2</missing>
<missing>a</missing>
</error>
I just want to return the values of the nodes "missing".
Thank you very much for your help.
Share Improve this question asked May 29, 2012 at 18:11 ZorkzydZorkzyd 1,0293 gold badges13 silver badges34 bronze badges 3-
Your code has
return el.textContent || el.innerText || el.nodeValue || '';
, so what's the problem? – Esailija Commented May 29, 2012 at 18:15 -
1
jsfiddle/BdCgL/1 works just fine, I only edited the
nodeValue
part for ie7 and ie8 but even before that they didn't alertundefined
, and ie9 worked fine unedited. – Esailija Commented May 29, 2012 at 18:20 - After debug with breakpoints, it appears that the interpreter XML of IE returns a different file than FF. I found the missing node elsewhere. Something like: data.lastchild.lastchild.lastchild.lastchild.childnode.text So, I have to search element by node name instead of exploring the tree… – Zorkzyd Commented May 29, 2012 at 18:45
2 Answers
Reset to default 3I found the solution on this site: http://www.chezneg.fr/leblog/chezneg-leblog.php?id_art=125
Seemingly, IE and FF interpreter don't read the XML Document in the same way.
For FF, error tag is located here: data.lastChild.lastChild.childNodes
For IE, error tag is located here: data.lastChild.lastChild.lastChild.lastChild.childNodes
(dixit the debugger)
Therefore, it's a better idea to locate the error tag via the following code: data.getElementsByTagName('error');
Many thanks anyway to Esailija for the help !
I have fixed close problem in IE9 by this code:
function getText(el) {
return el.textContent || el.text;
}