views:

638

answers:

1

I have a tree in flex built from an XML document into an XMLlist

In the XML the tags are all different and have a bunch of attributes each, and are not consistent.

When I publish the file I want the name of the folders in the tree to be the tag. It is easy with attributes.. "@id" or something similar, but I can't find what it could be to use the tag itself.

Thanks

+2  A: 

You'll have to use a custom label function to do that. Here's an example. Hope this helps.

<?xml version="1.0" encoding="utf-8"?>
<WindowedApplication xmlns="http://ns.adobe.com/mxml/2009"&gt;

  <Script>
    <![CDATA[
      [Bindable]
      public var xml:XML = <node1><node2a><node3><node4/></node3></node2a><node2b/></node1>;

      public function myLabelFunction(item:Object):String {
        var node:XML = XML(item);
        var nodeName:QName = node.name();
        return nodeName.localName;
      }
    ]]>
  </Script>

  <Tree width="100%" dataProvider="{xml}" labelFunction="myLabelFunction"/>

</WindowedApplication>
Christophe Herreman
I guess I feel better that it is as complicated as that rather than a simple call. Thanks!
mvrak