Page 1 of 1

NodeList as a result of getElementsByTagName?

Posted: Fri Aug 31, 2007 10:52 am
by moshe
In my script, I have

<data srcexpr="getMsg" name="msgInfo" method="post" namelist="id"/>

which returns (as can be verified in a log statement)

<?xml version="1.0" encoding ="UTF-8"?>
<messageInfo>
<ID>12</ID>
<text>This is the standard default test message.</text>
</messageInfo>

I then try to parse this in ECMAScript

<script>
rows = msgInfo.documentElement.getElementsByTagName("text")
if (rows.length > 0 ) {
TextToSend = rows[0].nodeValue
}
</script>

which does not work; this fails with a complaint about the array subscript. What's happening is that the value of rows, as seen in a log, is
<text>This is the standard default test message.</text>

and it seems to be a single element rather than a NodeList.

Evenif I try rows.nodeValue, treating this return value as a single Node instead of a NodeList, I get no data -- I get undefined.

I expect that I'm overlooking something obvious, but this methodology has worked for me in other (browser) contexts.

Posted: Fri Aug 31, 2007 11:07 am
by moshe
and one answer is:

nodeList.item(0).firstChild.data

seems to work -- that nodeValue tag is absolutely the wrong one -- but I've iterated through NodeList objects in the past using standard array notation, and I don't understand why it's not working here.

Posted: Fri Aug 31, 2007 11:16 am
by moshe
make that

nodeList.item(0).firstChild.data.toString()

otherwise, apparently, the type isn't text.

IVR NodeList as a result of getElementsByTagName

Posted: Fri Aug 31, 2007 1:00 pm
by support
Hi,

That is correct. Using the IVR system, you have to implement it in this way to make the type as text.

Regards,
Plum Support