3 Replies Latest reply on Jul 13, 2007 11:50 AM by ntsiii

    Displaying xml as a tree

    kilyas22
      I am trying to display a certain xml as a tree but I was haing some problems, so I decided to hard the xml into the mxml file itself and see what happens. I discovered something very confusing. The mxml code is as follows

      quote:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Panel xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300" >
      <mx:XMLList id="treeNew">
      <node value="Mail Box">
      <node value="Inbox">
      <node value="Marketing"/>
      <node value="Product Management"/>
      <node value="Personal"/>
      </node>
      <node value="Outbox">
      <node value="Professional"/>
      <node value="Personal"/>
      </node>
      <node value="Spam"/>
      <node value="Sent"/>
      </node>
      </mx:XMLList>

      <mx:Tree width="100%" height="100%" labelField="@label"
      showRoot="false" dataProvider="{treeNew}" />
      </mx:Panel>


      this doesnot work and instead of displaying as a tree, would display as xml itlself. If however instead of the xml hard coded abouve I try the following:-

      quote:

      <node label="Mail Box">
      <node label="Inbox">
      <node label="Marketing"/>
      <node label="Product Management"/>
      <node label="Personal"/>
      </node>
      <node label="Outbox">
      <node label="Professional"/>
      <node label="Personal"/>
      </node>
      <node label="Spam"/>
      <node label="Sent"/>
      </node>


      It would work fine, Please ot that I have replaced the value attribute with label. Please advise.
        • 1. Re: Displaying xml as a tree
          ntsiii Level 3
          Change: labelField="@label"
          to: labelField="@value"

          Get the idea?

          Tracy
          • 2. Re: Displaying xml as a tree
            kilyas22 Level 1
            Thanks, that really helped!!!! One more thing, lets suppose I have an xml as follows:-

            <?xml version="1.0" encoding="UTF-8"?>
            <system>
            <nodeList>
            <node value="Mail Box">
            <node value="Inbox">
            <node value="Marketing"/>
            <node value="Product Management"/>
            <node value="Personal"/>
            </node>
            <node value="Outbox">
            <node value="Professional"/>
            <node value="Personal"/>
            </node>
            <node value="Spam"/>
            <node value="Sent"/>
            </node>
            </nodeList>
            </system>

            But I want the tree to ignore system and nodeList, can tat be done? Specially if I don't have any value attribute in these elements.
            • 3. Re: Displaying xml as a tree
              ntsiii Level 3
              Having the Tree display ignore nodes the dataProvider is difficult.

              The best thing to do is to select/filter the XML. In this case, set the dataProvider = myXML.nodelist.node; this will put you below the nodelist node

              If you want to display all the nodes, but need more control over the lable, use labelFunction().. Here is an example below. It uses dataGrid, but the labelFunction would be the same.
              http://www.cflex.net/showFileDetails.cfm?ObjectID=564

              Tracy