Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Parsing an XML document

14 views
Skip to first unread message

ajis...@gmail.com

unread,
Sep 9, 2008, 7:54:27 PM9/9/08
to
Hi,

I am new to AJAX, and I am trying to parse out an XML response from
the server. The code works perfectly in IE, but does not work in
FireFox. Here is my code. Can anyone suggest the issue or an
alternative.

Thanks in advance.
Albert
function processGetStates() {
var frmState = document.getElementById(wa_state);
removeAllOptions(frmState);
if (req.readyState == 4) {
if (req.status == 200) {
// alert(req.responseText);
xmlDoc = req.responseXML;
// var root = xmlDoc.getElementsByTagName("STATES")[0];
// alert(root.length);
var states = xmlDoc.getElementsByTagName("item");
alert(states.length);
// var state = states[0].getElementsByTagName("STATE")
[0].childNodes[0].nodeValue;
// var description =
states[0].getElementsByTagName("DESCRIPTION")
[0].childNodes[0].nodeValue;
// alert(state + description);
// alert(states.length);
for (var i=0; i<states.length; i++)
{
var state = states.item(i).getElementsByTagName("STATE")
[0].childNodes[0].nodeValue;
var description =
states.item(i).getElementsByTagName("DESCRIPTON")
[0].childNodes[0].nodeValue;
addOption(frmState, state, description);
}
// alert(req.responseText);
}
}
}
as you can see I have tried everything and none of these syntax works
in FireFox.

Thanks.
Albert

Martin Honnen

unread,
Sep 10, 2008, 7:46:10 AM9/10/08
to
ajis...@gmail.com wrote:

> as you can see I have tried everything and none of these syntax works
> in FireFox.

Post a URL to the XML document you are trying to read out data from and
explain which data exactly you are looking for. If you don't have a URL
then post a relevant sample of the XML, cut to a minimum but still
complete enough to show the structure.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Roland de Ruiter

unread,
Sep 10, 2008, 9:25:39 AM9/10/08
to
On 10-9-2008 1:54, ajis...@gmail.com wrote:
> Hi,
>
> I am new to AJAX, and I am trying to parse out an XML response from
> the server. The code works perfectly in IE, but does not work in
> FireFox. Here is my code. Can anyone suggest the issue or an
> alternative.
>
> Thanks in advance.
> [...]

> var states = xmlDoc.getElementsByTagName("item");
> [...]

> var state = states.item(i).getElementsByTagName("STATE")
> [...]

I notice you are searching for tags with both upper- and lowercase names.
Since element and attribute names are case sensitive in XML, could it be
that you don't find matching elements because all elements in the
received document have lowercase names, while you are looking for
elements with uppercase names?
--
Regards,

Roland

Tei

unread,
Sep 12, 2008, 7:01:16 AM9/12/08
to dev-...@lists.mozilla.org
On Wed, Sep 10, 2008 at 1:54 AM, <ajis...@gmail.com> wrote:
> Hi,
>
> I am new to AJAX, and I am trying to parse out an XML response from
> the server. The code works perfectly in IE, but does not work in
> FireFox. Here is my code. Can anyone suggest the issue or an
> alternative.


how much code you have to write?

if his more than trivial code, i suggest you to search for a function
that read a xml tree, and generate a javascript object with all the
information mirrored (json alike). or directly, use json.

json is easier to read and to use, less error prone

also, json will automatically handle for your the data encoding (UTF8)
in a transparent js to js way.

good code sould be easy to write and read, and not this mess where the
syntax obscure the algorithm.

I am totally pro-XML everywhere else, but parsing in js.

Luke Yan

unread,
Sep 30, 2008, 10:31:18 PM9/30/08
to
hi,

have you checked whether the response header "Content-Type" is "text/xml"?
and you can get the value by:
xmlResponse.getResponseHeader("Content-Type");

thanks
luke

在 Tue, 9 Sep 2008 16:54:27 -0700 (PDT) 时, ajis...@gmail.com 写了:
--

0 new messages