3 Replies Latest reply on Jul 24, 2006 4:24 PM by Josh Johnson

    XMLList to External XML File

    Josh Johnson Level 1
      Hi All,

      I'm new to Flex, but I've been impressed with it so far. I was able to create a simple app, where things like navigation trees and table data were populated based on XML stored inside mx:XMLList tags inside the main document. In order to clean things up, I thought I'd move the data into external XML files. I copied the data out to the files, and verified the data always had a single top-level node. I then noted that mx:XMLList doesn't support the 'source' attribute, so converted to using mx:XML tags inside the application mxml. The application now compiles, but entirety of the XML hierarchy displays as a single node, instead of being parsed into tree nodes. Any idea what I'm missing here? And thanks in advance for going easy on the noob. ;-)

      - Josh
        • 1. Re: XMLList to External XML File
          Josh Johnson Level 1
          Answered my own question, but posting for posterity. The rule I saw about needing to have only a single top-level node seems to be the problem. As soon as I removed that and went back to the basic data structure, all was well.
          • 2. Re: XMLList to External XML File
            Josh Johnson Level 1
            Spoke too soon. Looks like that top node thing is right, as it's only passing in the first node from each xml datasource. It must've been doing that before, but since the top-node didn't have a label, it displayed all the children as the label.

            So by adding the top-level node to the XML, my guess is that when I call my data from the dataProvider, I'll have to add something to bypass this extra layer of hierarchy, right?

            Currently my app code has:
            <mx:XML id="deviceTree" source="deviceTree.xml" />
            <snip/>
            <mx:Tree dataProvider="{deviceTree}" />

            and my XML (deviceTree.xml) with the new added top node is now:
            <?xml version="1.0" encoding="utf-8"?>
            <devices>
            <node label="Foo">
            <node label="Foo1" />
            <node label="Foo2" />
            </node>
            <node label="Bar">
            <node label="Bar1" />
            <node label="Bar2" />
            </node>
            </devices>

            I tried changing the dataProvider to {deviceTree.devices} but to no avail. Can someone throw me a line?
            • 3. XMLList to External XML File
              Josh Johnson Level 1
              Again, answering myself for posterity.

              For tree data, the top node is implied, so I just had to change the dataProvider to {deviceTree.node}. For table data, it was a little more difficult, where instead of linking to it using an <mx:XML> tag, I instead linked to it as an <mx:Model>, and then created an <mx:ArrayCollection> where the source was specified as the {[XML id].[node]}. (again the top node was already implied)