2 Replies Latest reply on May 3, 2007 6:36 AM by JKohn99

    complex xml in tree control

    snafu7x7 Level 1
      every example you see online is trivial and utterly useless for practical programming purposes...typically you'll see something like this:

      <mx:XML format="e4x" id="myMenuModel">
      <root label="Menu">
      <menuitem label="MenuItem A">
      <menuitem label="SubMenuItem 1-A"/>
      <menuitem label="SubMenuItem 2-A" />
      <menuitem label="MenuItem B"/>
      <menuitem label="MenuItem C" type="check"/>
      <menuitem type="separator"/>
      <menuitem label="MenuItem D">
      <menuitem label="SubMenuItem 1-D" type="radio" groupName="one"/>
      <menuitem label="SubMenuItem 2-D" type="radio" groupName="one"/>
      <menuitem label="SubMenuItem 3-D" type="radio" groupName="one"/>

      ...just hard coded simplistic xml which is fine and dandy if you have a simple xml schema and all the leaves of your tree can be keyed off the same "label" attribute. But what if you have a complex, deeply nested XML file that doesn't follow this nice pattern? What if I want to pull different attributes from different levels in the tree to display, is that even possible? Or what if I dont want to use the attribute at all for my display label in the tree, what if I want to use an element node name? Like for example, say I had:

      <department label="marketing">
      <employee name="Eric Cartman" Age="8">
      <name>mr. kitty</name>

      Is there a way I can build my tree to use the department 'label' attribute for the top level, the employee 'name' attribute for the second level and the <type> element nested under <interest> for the third level?

      I confess I'm a Flex newbie but any other language I've worked provides a mechanism to tailor this sort of thing to individual business cases. Any insight would be greatly appreciated.

      thank you.

        • 1. Re: complex xml in tree control
          peterent Level 2
          I wrote some articles about the Tree control on my blog; do a search for Tree to bring them out.

          When you have complex nodes to display in the Tree you must use a labelFunction.
          • 2. Re: complex xml in tree control
            Another approach is parse your complex xml into objects and then create your own
            tree datadescriptor. This is described in the help. Search on "custom tree datadescriptor"

            We use this approach because the xml we want to display in a tree does not fit nicely. So we wrote a parser that converts the xml into "TreeObjects" (our class) and created the custom tree datadescriptor to handle it. When we create the tree object we can control the data used for the label so it displays correctly.