# Call XML node with variable

**URL:** <https://forum.kirupa.com/t/call-xml-node-with-variable/216046>\
**Category:** Uncategorized\
**Created:** [February 13, 2007, 8:41am UTC](https://forum.kirupa.com/t/call-xml-node-with-variable/216046 "2007-02-13T08:41:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![overtune](https://avatars.discourse-cdn.com/v4/letter/o/e480ec/32.png) [@overtune](https://forum.kirupa.com/u/overtune)\
**Post date:** [February 13, 2007, 8:41am UTC](https://forum.kirupa.com/t/call-xml-node-with-variable/216046/1 "2007-02-13T08:41:14Z")

</div>

I’m working on a newsboard for a site that I develop. I use an xml file for the news text. I loop out the news headers first, and then make them a link. When the link is clicked a as function starts. I send the node id to the function. The function is going to display the news text. It all works, the headers is displayd, and when I click on one of them the function starts, and I get the right id number when I trace it in the function.

But, when I use the id variable to call a childNode (childNode[id]), I just get the message “undefined”. If I insert a number instead (childNode[0]) it all works. Why can’t I use the variable “id”? Id does contain the number…

Here is the code:

[as2]  
newsXML = new XML();  
newsXML.ignoreWhite = true;  
newsXML.onLoad = ladda;  
newsXML.load(“news.xml”);

function ladda(success) {  
//trace(“loaded”);  
antal\_news = 1;

for (i=0; i\<antal\_news; i++) {  
if (newsXML.firstChild.childNodes\* != null) {  
news\_text += “\<a href=‘asfunction:test, “+i+”’\>”+newsXML.firstChild.childNodes \*.firstChild.firstChild.nodeValue+"\</a\>\<br /\>";  
antal\_news++;  
}  
else {  
antal\_news = 0;  
}  
}  
}

function test(id:Number) {  
trace(id);  
news\_text += newsXML.firstChild.childNodes[id].firstChild.firstChild.nodeValue+"\<br /\>";  
news\_text += newsXML.firstChild.childNodes[id].firstChild.nextSibling.firstChild;  
}  
[/as2]
