NodeList as a result of getElementsByTagName?
Posted: Fri Aug 31, 2007 10:52 am
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.
<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.