# Creating variables in a loop and assigning them non empty XML values

**URL:** https://forum.kirupa.com/t/creating-variables-in-a-loop-and-assigning-them-non-empty-xml-values/322743
**Category:** flash
**Created:** [June 1, 2011, 2:08pm UTC](https://forum.kirupa.com/t/creating-variables-in-a-loop-and-assigning-them-non-empty-xml-values/322743 "2011-06-01T14:08:37Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![decimal](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@decimal](https://forum.kirupa.com/u/decimal)
#### Post date: [June 1, 2011, 2:08pm UTC](https://forum.kirupa.com/t/creating-variables-in-a-loop-and-assigning-them-non-empty-xml-values/322743/1 "2011-06-01T14:08:37Z")

</div>

Here is the structure of the XML file:

```php

<xmlfile>
<page></page>

<page>
 <source></source>
 </page>
</xmlfile>

```

Some “page” nodes contain the extra “source” node. What I’m currently doing is looping through all the page nodes and looking for any source nodes. If there is a source node, I create a variable, and want to assign it a value of the contents of the “source” (HTML).

Here’s the AS:

```php
numNodes = myXML.firstChild.childNodes.length;
        for(i=0; i<numNodes; i++) {
            pSource = myXML.firstChild.childNodes*.firstChild.nextSibling;
            if (pSource != null) {
                this["page_source"+i] = pSource;
                trace("page_source"+i);
            }
        }

```

The variables are named according to the page they’re on, i.e. the above example would be page\_source2 since no source node is in the first page. So, I want page\_source2 to hold the value of the node, but all I’m getting back is the page\_source name. How can I get the dynamically created variable to hold the node value?
