Welcome, Guest
  • Author Topic: XML + create XMLList from each parent node  (Read 1603 times)

    worked

    • Seasoned Programmer
    • ***
    • Posts: 129
      • View Profile
      • Email
    XML + create XMLList from each parent node
    « on: 05/20/10, 10:10 »
    Hey there-  I have a very simple XML file and need to extract each parent node into it's own XMLList, for later altering.  For example:

    XML:
    Code: [Select]
    <treeMenu>
      <item txt="1">
        <item txt="A">
          <item txt="A1"></item>
          <item txt="A2"></item>
        </item>
      </item>
    </treeMenu>

    How would I capture each "item" parent into it's own xmlList, ignoring any "item" node that does not contain children?  Thanks, any help is appreciated!
    « Last Edit: 05/20/10, 10:14 by worked »

    worked

    • Seasoned Programmer
    • ***
    • Posts: 129
      • View Profile
      • Email
    Re: XML + create XMLList from each parent node
    « Reply #1 on: 05/20/10, 11:42 »
    Ok, So I've made some headway, but am slightly confused on one thing:
    XML:
    Code: [Select]
    <treeMenu>
      <item txt="1">
        <item txt="a">
          <item txt="a1">
            <item txt="a1-1"/>
            <item txt="a1-2"/>
          </item>
          <item txt="a2">
            <item txt="a2-1">
              <item txt="a2-a1">
                <item txt="a2-a2"/>
              </item>
            </item>
          </item>
        </item>
      </item>
    </treeMenu>

    With the above xml file, I'm able to decipher which nodes contain Complex Content, which in-turn gives me every parent node in the file. However, for some reason when I trace those Booleans i receive "false" for any parent node that contains only one child.  Here's my code:

    AS3:
    Code: [Select]
    var btnXML:XML = new XML(e.target.myXML);
    var btnList:XMLList = btnXML..button;
    for each(btnXML in btnList){
      trace(btnXML.@id + " - " + btnXML.button.hasComplexContent());
    }
    trace output:
    1 - true
    a - true
    a1 - true
    a1-1 - false
    a1-2 - false
    a2 - true
    a2-1 - true
    a2-a1 - false : should be true
    a2-a2 - false
    « Last Edit: 05/20/10, 11:43 by worked »

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: XML + create XMLList from each parent node
    « Reply #2 on: 05/20/10, 12:41 »
    try to avoid the dash, it might be seen as operator for subtration ;) - and after you have a non numeric value first, it will be false, because you cannot subtract a number from a string.
    happy flashing
    8)
    Ronald

    worked

    • Seasoned Programmer
    • ***
    • Posts: 129
      • View Profile
      • Email
    Re: XML + create XMLList from each parent node
    « Reply #3 on: 05/22/10, 05:44 »
    Thanks for responding!  I kept digging deeper and found the issue... thanks though!
    « Last Edit: 05/24/10, 20:39 by worked »