# Dynamic name in loop to search XML

**URL:** <https://forum.kirupa.com/t/dynamic-name-in-loop-to-search-xml/634585>\
**Category:** flash\
**Created:** [May 5, 2016, 5:49pm UTC](https://forum.kirupa.com/t/dynamic-name-in-loop-to-search-xml/634585 "2016-05-05T17:49:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![McLucky](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@McLucky](https://forum.kirupa.com/u/McLucky)\
**Post date:** [May 5, 2016, 5:49pm UTC](https://forum.kirupa.com/t/dynamic-name-in-loop-to-search-xml/634585/1 "2016-05-05T17:49:15Z")

</div>

Hi all,

I’m kinda stuck on this. I have a loop that counts how many xml nodes contain data.

One xml node looks like this:

[code]  
7553130  
INDE IDCL75BH  
\<C01\_dim\>70x90x70\</C01\_dim\>  
\<C01\_wght\>30\</C01\_wght\>  
\<C02\_dim/\>  
\<C02\_wght/\>  
\<C03\_dim/\>  
\<C03\_wght/\>  
\<C04\_dim/\>  
\<C04\_wght/\>  
\<C05\_dim/\>  
\<C05\_wght/\>  
\<C06\_dim/\>  
\<C06\_wght/\>

[/code]

Now I would like to use a loop:  
(variable k is valid and this is not the problem)

`
for (var m:int = 1; m<7 ; m++){
      if( xmlArtData.Artikel[k].['C0' + m + '_dim'] != "" ){
            intNumberOfColli++;
       }    
} `

The line:

```auto

```

Gives the following errors:

Scene 1, Layer ‘Layer 2’, Frame 1, Line 654 1084: Syntax error: expecting identifier before leftbracket.  
Scene 1, Layer ‘Layer 2’, Frame 1, Line 654 1084: Syntax error: expecting rightparen before rightbracket.

Any tips would be appreciated.

Thanks !

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [May 5, 2016, 6:25pm UTC](https://forum.kirupa.com/t/dynamic-name-in-loop-to-search-xml/634585/2 "2016-05-05T18:25:39Z")

</div>

There’s no dot between [k] and [‘C0’ + m + ‘\_dim’] just like there’s no dot between Artikel and [k]:

```
xmlArtData.Artikel[k]['C0' + m + '_dim']

```

If you use E4x you could do something like

```
Article.children().(toString() !== '').length()

```

or

```
Article.children().(children().length()).length()
```

---

<div class="post-metadata">

**Author:** ![McLucky](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@McLucky](https://forum.kirupa.com/u/McLucky)\
**Post date:** [May 5, 2016, 6:44pm UTC](https://forum.kirupa.com/t/dynamic-name-in-loop-to-search-xml/634585/3 "2016-05-05T18:44:25Z")

</div>

Thank you !

I’ll look into E4x too, looks interesting when handling XML

One more question though

```auto
function fncSearchLabelData(SearchArtNr) : Array {
    
    var intNumberOfColli:int = 0;
    var arrResult:Array;
    
    for (var k:int = 0; k<xmlArtData.*.length(); k++){
        
            if(xmlArtData.Artikel[k].ArtNr == SearchArtNr){
                
                strDescription = xmlArtData.Artikel[k].Descr;
                
                for (var m:int = 1; m<7 ; m++){
                    if( xmlArtData.Artikel[k]['C0' + m + '_dim'] != "" ){
                        intNumberOfColli++;
                    } //end if
                } //end for    
                
                arrResult = [strDescription,intNumberOfColli]
                return(arrResult);
                
                break;
                
            } //end if
    } //end for
    
    return(arrResult);
    
} //end fncSearchLabelData[/code]

If the code above reaches the 'break' statement, will this break the main loop :
[code]for (var k:int = 0; k<xmlArtData.*.length(); k++){ 
```

Thnx

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [May 5, 2016, 9:02pm UTC](https://forum.kirupa.com/t/dynamic-name-in-loop-to-search-xml/634585/4 "2016-05-05T21:02:10Z")

</div>

The break won’t break the loop because it will never be encountered. The return above it would break out of the function before the break can even be read.

If the return weren’t there, yes, it would break the main loop since thats the loop its in. If it were in the inner loop it would break, and only break, the inner loop. If you want something in an inner loop to break an outer loop, you can use a label.

```
outer: for (var k:int = 0; k<xmlArtData.*.length(); k++){
    // ...
    for (var m:int = 1; m<7 ; m++){
        // ...
        break outer; // breaks all loops up to, and including, the one labeled outer
    }
}
```

---

<div class="post-metadata">

**Author:** ![McLucky](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@McLucky](https://forum.kirupa.com/u/McLucky)\
**Post date:** [May 6, 2016, 8:23am UTC](https://forum.kirupa.com/t/dynamic-name-in-loop-to-search-xml/634585/5 "2016-05-06T08:23:36Z")

</div>

Thanks for explaining and the tip about the label 🙂
