4 Replies Latest reply on Jan 5, 2009 7:27 PM by ntsiii

    Remote XML Dataprovider for Tree control

    alexenk
      Trying to create a tree class that instead of loading the XML node list from inside the application, to try and read from an external file entitled 'nodes.xml'. I have tried altering snippets of code I found from various sources and this is the current iteration I am on. Please advise on how to fix this!

      Note: In the XML file itself I have tried with and without the <mx:XMLList> tags wrapping it, neither seems to work. Here is a link to a live demo: http://81.100.103.105/flex_dev/treeExample.html


      Many Thanks
        • 1. Re: Remote XML Dataprovider for Tree control
          matthew horn Level 3
          Alex, I was able to make this work by cleaning the XML file a little. Remove the XMLList and the ?xml lines, so it looks like this:

          <nodes label="Departments">
          <node label="1">
          <node label="A"/>
          <node label="B"/>
          <node label="C"/>
          </node>
          <node label="2">
          <node label="A"/>
          <node label="B"/>
          </node>
          <node label="3"/>
          <node label="4">
          <node label="A"/>
          <node label="B">
          <node label="B1"/>
          <node label="B2"/>
          </node>
          <node label="C"/>
          </node>
          </nodes>

          FWIW, if the XML file is static (ie, wont change at run time), then you might consider using the mx:Model tag. It has less overhead than the URLLoader and it bakes the XML into the SWF at compile time.

          hth,
          matt horn
          flex docs
          • 2. Re: Remote XML Dataprovider for Tree control
            alexenk Level 1
            Thanks alot Matt, this will eventually be a dynamicly changing XML file, but its in its base stages atm
            • 3. Re: Remote XML Dataprovider for Tree control
              alexenk Level 1
              It appears the problem was whitespace in the XML File
              • 4. Re: Remote XML Dataprovider for Tree control
                ntsiii Level 3
                "...consider using the mx:Model tag..." I hate that tag. I reduces your XML into a tree of dynamic objects.

                Use mx:XML instead, you will have nice e4x XML to work with.

                To the original poster: Do you understand why the <mx:XMLList> node was a problem? XMLList is an actionscript object. Don't mix that with plain XML.

                "whitespace" is rarely a problem in XML. This, "<mx:XMLList>" is problematic as it introduces xml namespace without a namespace declaration. That may not even be valid xml. Open your xml file in IE to make sure it is valid.

                Tracy