Note that there are some explanatory texts on larger screens.

plurals
  1. POarraycollection with repeated nodes
    primarykey
    data
    text
    <p>In the resultHandler of an HTTPService call, I have assigned a repeating node to an arrayCollection. Inside that repeating node are other nodes that sometimes repeat and sometimes do not. For instance, here the <strong>option</strong> node repeats inside <strong>options</strong>.</p> <pre><code>&lt;response&gt; &lt;options&gt; &lt;option&gt; &lt;var1&gt; part1 &lt;/var1&gt; &lt;var2&gt; part2 &lt;/var2&gt; &lt;/option&gt; &lt;option&gt; &lt;var1&gt; part1 &lt;/var1&gt; &lt;var2&gt; part2 &lt;/var2&gt; &lt;/option&gt; &lt;/options&gt; &lt;options&gt;.... &lt;/response&gt; </code></pre> <p>And sometimes it does not repeat, like this.</p> <pre><code> &lt;response&gt; &lt;options&gt; &lt;option&gt; &lt;var1&gt; part1 &lt;/var1&gt; &lt;var2&gt; part2 &lt;/var2&gt; &lt;/option&gt; &lt;/options&gt; &lt;options&gt;.... &lt;/response&gt; </code></pre> <p>I am running into actionscript errors in my for loop. How do I account for both cases?</p> <p>Here is my for loop assigning objects to value objects:</p> <pre><code>protected function xml_resultHandler(event:ResultEvent):void { var data:ArrayCollection = xml.lastResult.response.option; var valueobjects:valueObject; for each (var characteristic:Object in data) { valueobject = new valueobject; valueobject.var1 = characteristic.option[0].var1; valueobject.var2 = characteristic.option.var2; datamodel.addItem(valueobject); } </code></pre> <p>}</p> <p>In this sample code, assigning var1 will break if there are not multiple option nodes, and var2 will break if there are multiple object nodes. I could break it apart and iterate over them separately, but is there a more eloquent solution?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload