Xml.children() returns grand-children and gr8-gran-children

I’m making a OSX-finder-type file browser in CS4.
The Structure for the folder and files is being generated by a PHP in a XML, heres an example:
(sorry the xml is not sorted, but the command i’m using in php doesn’t sort it)


<root>
  <dir name="images">
    <file name="1.jpg" width="438" height="292" size="40049" modified="1258228378" created="1258228378"/>
    <file name="6.jpg" width="291" height="437" size="37454" modified="1258228387" created="1258228387"/>
    <dir name="subimages">
      <file name="30.jpg" width="267" height="400" size="43982" modified="1258228461" created="1258494835"/>
      <file name="21.jpg" width="174" height="260" size="16353" modified="1258228436" created="1258494829"/>
      <file name="34.jpg" width="289" height="192" size="29111" modified="1258228471" created="1258494837"/>
      <file name="3.jpg" width="438" height="292" size="62045" modified="1258228382" created="1258494835"/>
      <file name="29.jpg" width="180" height="271" size="21400" modified="1258228459" created="1258494834"/>
      <file name="24.jpg" width="178" height="267" size="30146" modified="1258228446" created="1258494832"/>
      <file name="22.jpg" width="195" height="292" size="33520" modified="1258228442" created="1258494830"/>
      <file name="32.jpg" width="197" height="296" size="17980" modified="1258228467" created="1258494836"/>
      <file name="27.jpg" width="246" height="369" size="20109" modified="1258228453" created="1258494834"/>
      <file name="23.jpg" width="196" height="293" size="26977" modified="1258228444" created="1258494832"/>
      <file name="26.jpg" width="196" height="295" size="21835" modified="1258228450" created="1258494833"/>
      <dir name="more subimages">
        <file name="16.jpg" width="320" height="214" size="31321" modified="1258228423" created="1258546650"/>
        <file name="12.jpg" width="293" height="439" size="37756" modified="1258228412" created="1258546649"/>
        <file name="10.jpg" width="400" height="267" size="37452" modified="1258228402" created="1258546648"/>
        <file name="11.jpg" width="438" height="292" size="42396" modified="1258228410" created="1258546648"/>
        <file name="17.jpg" width="400" height="267" size="67997" modified="1258228427" created="1258546651"/>
        <file name="15.jpg" width="290" height="193" size="35146" modified="1258228422" created="1258546650"/>
        <file name="13.jpg" width="290" height="193" size="14166" modified="1258228413" created="1258546649"/>
        <file name="19.jpg" width="195" height="292" size="28347" modified="1258228432" created="1258546651"/>
        <file name="18.jpg" width="292" height="195" size="37655" modified="1258228429" created="1258546651"/>
        <file name="14.jpg" width="177" height="266" size="21647" modified="1258228417" created="1258546649"/>
      </dir>
      <file name="20.jpg" width="195" height="292" size="34199" modified="1258228433" created="1258494829"/>
      <file name="25.jpg" width="439" height="292" size="45792" modified="1258228448" created="1258494833"/>
      <file name="31.jpg" width="270" height="406" size="41123" modified="1258228466" created="1258494836"/>
      <file name="33.jpg" width="292" height="439" size="67274" modified="1258228469" created="1258494837"/>
      <file name="28.jpg" width="179" height="269" size="20383" modified="1258228457" created="1258494834"/>
    </dir>
    <file name="9.jpg" width="400" height="267" size="32518" modified="1258228397" created="1258228397"/>
    <file name="8.jpg" width="196" height="294" size="19890" modified="1258228393" created="1258228393"/>
    <file name="2.jpg" width="198" height="298" size="26646" modified="1258228380" created="1258228380"/>
    <file name="5.jpg" width="197" height="294" size="20740" modified="1258228385" created="1258228385"/>
    <file name="4.jpg" width="403" height="268" size="31353" modified="1258228384" created="1258228384"/>
    <file name="7.jpg" width="398" height="265" size="55980" modified="1258228390" created="1258228390"/>
  </dir>
  <file name="filelist5.php" size="320" modified="1258233091" created="1258233091"/>
  <dir name="php">
    <file name="filelist5.php" size="2432" modified="1258243295" created="1258243295"/>
  </dir>
</root>

The XML loads fine in my SWF and I can navigate through it perfecly, EXCEPT:

  1. When I ask to see the children of any folder, it returns me all the grand children and great grand children as well.
  2. The children() and the elements() commands return the same values.
  3. I’ve also tried to get the XML parent by its index, but the result is the same

Here’s the code i’m using to get the children:


for each (var item in xmlTree.descendants('dir')){
     if (item.@name == 'subimages'){
          trace (item.children());
     }
}

and here’s what I get:


<file name="30.jpg" width="267" height="400" size="43982" modified="1258228461" created="1258494835"/>
<file ***"/>
<file name="26.jpg" width="196" height="295" size="21835" modified="1258228450" created="1258494833"/>
**<dir name="more subimages">
  <file name="16.jpg" width="320" height="214" size="31321" modified="1258228423" created="1258546650"/>
  <file ***"/>
  <file name="14.jpg" width="177" height="266" size="21647" modified="1258228417" created="1258546649"/>
</dir>**
<file name="20.jpg" width="195" height="292" size="34199" modified="1258228433" created="1258494829"/>
<file ***"/>
<file name="28.jpg" width="179" height="269" size="20383" modified="1258228457" created="1258494834"/>

and here’s what I was looking for:


<file name="30.jpg" width="267" height="400" size="43982" modified="1258228461" created="1258494835"/>
<file ***"/>
<file name="26.jpg" width="196" height="295" size="21835" modified="1258228450" created="1258494833"/>
**<dir name="more subimages"></dir>**
<file name="20.jpg" width="195" height="292" size="34199" modified="1258228433" created="1258494829"/>
<file ***"/>
<file name="28.jpg" width="179" height="269" size="20383" modified="1258228457" created="1258494834"/>

I can try any folder ‘images’, ‘subimages’ and everytime with any command I get gran children too.

  • Is this possibly a bug with the children() method or is this expected behaviour?
  • Could there be something wrong with my XML construction?
  • Has anyone encountered a problem like this, and possibly a solution?