3 Replies Latest reply on Apr 27, 2006 7:17 AM by eyahav

    recursion in XML


      I hope it's not a too silly question...
      I am building an organizational chart using flash and XML. I want to present 2 levels at the time (manager and subordinates), with an icon next to each subordinate that also has subordinates. When this icon is clikced, the chart changes to the next level - the subordinated that was clicked takes the manager's place (i.e., appears in first level) and the next level is presented under it.

      I managed to do it hard coded, but I don't know how to make it recursive.
      this is the code that needs to change every time:

      employeesNode = this.firstChild.childNodes[0];

      Every time a subordinate is clicked, I need to append this:

      so that I get:
      in the first time, and
      this.firstChild.childNodes[0].childNodes[1].childNodes[subNumber[0]].childNodes[1].childNo des[subNumber[1]]

      Can anyone help?
      Thanks so much,
        • 1. Re: recursion in XML
          blemmo Level 1
          Try the attached code. It's not recursive, but this doesn't have to be bad.
          I think this isn't the best possible structure (for the xml), but I guess you have your reasons.

          The function takes in a XMLNode, and returns one. Use it like this:
          employeesNode = this.firstChild.childNodes[0];
          resultNode = parseNode( employeeNode, 1 ) // gets employeeNode.childNodes[1].childNodes[subNumber[0]]
          resultNode = parseNode( employeeNode, 2 ) // gets employeeNode.childNodes[1].childNodes[subNumber[0]].childNodes[1].childNodes[subNumber[1] ]


          • 2. Re: recursion in XML
            eyahav Level 1
            Thanks for the quick reaponse!
            But it doesn't work... I get undefined on res...

            Even if I define:
            var employeesNode:XMLNode = local_xml.firstChild.childNodes[0];
            the first time I load the xml file, and then try:
            I get undefined.

            I think it's because employeesNode is the actual xml data, and not the path (if I trace it alone I get a part of the xml itself), so you cannot append a path to it. is there any way I can get the path of employeesNode?

            Thanks for your help!!!

            • 3. Re: recursion in XML
              eyahav Level 1
              no, wait... as always in these things, a stupid mistake. I now defined employeesNode as an xmlNode directly on the root. It seems to work! I have another error now but in general it seems ok.
              You are a genius and a true saint. thank you!!!