Am trying to read an XML response using getElementsByTagName
:
var rows = items.responseXML.getElementsByTagName("z:row");
for (var i=0; i<rows.length; i++)
{
//do something
}
Above code works fine in Firefox and IE but in chrome it throws null.. i mean it does not get any data.. when i alert
the rows.length
it gives me 0
always in chrome.
Then i searched in google and understood the issue is with xsd:element
, then i changed "z:row"
to only "row"
. Then it worked in Chrome but Firefox and IE returned 0
for rows.length
.
Is there any method which across all browsers?
This is what I use:
function byTagNS(xml,tag,ns) {
return xml.getElementsByTagNameNS
? xml.getElementsByTagNameNS(ns,tag)
: xml.getElementsByTagName(ns+":"+tag);
}
With in your case:
byTagNS(responseXML, "row", "z")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With