This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Mozilla XML > July 2005 > I am getting crazy. Can't access XML contents in Firefox.





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author I am getting crazy. Can't access XML contents in Firefox.
leodippolito@gmail.com

2005-07-21, 7:37 pm



Hello sirs,


I am trying to send a POST request to a webservice on the click of a
button. This will return me an XML document with a list of combo box
items.


The problem: in FIREFOX, when the get the XmlDocument from the
XmlHttpRequest object, I can't access its contents. I keep getting
empty strings and "null".


This is my code:


---


function GetComboBoxItems(p_strType, p_strCode)
{
var objParameters =3D new Array();
objParameters[0] =3D p_strType;
objParameters[1] =3D p_strCode;


var objHttpRequest =3D

SendRequest("/MeuWebService/MyWebService.asmx/GetComboBoxIte=ADms",
objParameters);


alert(objHttpRequest.responseT=ADext); // alerts the XML doc
(see below)


/*


this is the XML document:


<?xml version=3D"1.0" enconding=3D"utf-8"?>
<ReturnDocument>
<ComboItem>
<Key>1</Key>
<Description>My first item</Description>
</ComboItem>
<ComboItem>
<Key>2</Key>
<Description>My second item</Description>
</ComboItem>
</ReturnDocument>


*/


alert(objHttpRequest.responseX=ADML); // alerts '[object
XMLDocument]'


var XmlDoc =3D objHttpRequest.responseXML;


var arrTemp =3D
XmlDoc.documentElement.getElem=ADentsByTagName("ComboItem");


alert(arrTemp.length); // alerts '2'


// show contents (Firefox)
for(var i =3D 0; i < arrTemp.length; i++)
{
alert(arrTemp[i].childNodes[0]=AD.nodeValue); // alerts empty
string
alert(arrTemp[i].childNodes[1]=AD.nodeValue); // alerts
'null'
}


/*
// show contents (IE) - works perfectly
for(var i =3D 0; i < arrTemp.length; i++)
{
alert(arrTemp[i].childNodes[0]=AD.text);
alert(arrTemp[i].childNodes[1]=AD.text);
alert(arrTemp[i].childNodes[2]=AD.text);
} */



}


---

I searched everywhere for a logic explanation, but couldn't find any.


In IE it works perfectly. What am I doing wrong?=20


TIA,=20
Leonardo

Neil Deakin

2005-07-22, 7:20 pm

leodippolito@XXXXXXXXXX wrote:
>
> <?xml version="1.0" enconding="utf-8"?>
> <ReturnDocument>
> <ComboItem>
> <Key>1</Key>
> <Description>My first item</Description>
> </ComboItem>
> <ComboItem>
> <Key>2</Key>
> <Description>My second item</Description>
> </ComboItem>
> </ReturnDocument>
>


>
> // show contents (Firefox)
> for(var i = 0; i < arrTemp.length; i++)
> {
> alert(arrTemp[i].childNodes[0]_.nodeValue); // alerts empty
> string


The first child is the blank space between the <ComboItem> and the
<Key>. The second child is a <Key> element and elements have a nodeValue
of null.

/ Neil
Jonathan Bond

2005-07-22, 7:20 pm

For example:

for(var i = 0; i < arrTemp.length; i++) {
alert(arrTemp[i].childNodes[0]_.firstChild.data);
}

is what your looking, when debugging it's a good idea to check

arrTemp[i].childNodes[0]_.nodeType = 1 (it's an element)

jon


Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews