4 Replies Latest reply on Apr 12, 2009 9:50 PM by LPVOID32

    Tree dataSource as xml from webservice


      I have a webservice in asp.net that returns an XMLDocument.  i want to populate a tree control. However, when it loads i see the entire xml doc in the first 3 branches. when i drill down a few levels i see the correct labels.  it's including the get_tree_dataResponse and get_tree_dataResult tags in the tree as well as the root node which i set to false in the tree conrtrol.  once i drill down past those 2 it fills the name correctly.  What am i doing wrong?  here's my code


                  import mx.controls.Alert;
                  import mx.collections.XMLListCollection;
                  import mx.rpc.events.ResultEvent;
                  import mx.collections.ArrayCollection;
                  private var mydata:ArrayCollection;
                  //private var treeData:XMLListCollection;
                  private var treeData:XMLListCollection = new XMLListCollection();
                  private function resultHandlerTree(event:ResultEvent):void{
                      //treeData = new XMLListCollection(new XMLList(event.result));
                      treeData.source = new XMLList(event.result);


                  private function resultHandlerGrid(event:ResultEvent):void{
                      mydata = event.result.SECTIONS.SECTION;


          <mx:WebService id="csService" wsdl="http://mywebservice/service1.asmx?WSDL"
              showBusyCursor="true" useProxy="false">
              <mx:operation name="get_tree_data" result="resultHandlerTree(event)"
                  resultFormat="e4x" fault="Alert.show(event.fault.faultString, 'Error');">
              <mx:operation name="get_sections_by_subj"
                  result="resultHandlerGrid(event)" fault="Alert.show(event.fault.faultString, 'Error');">


          <mx:HBox height="100%">
              <mx:Panel height="80%" width="350" title="Browse" fontSize="10" >
                  <mx:Tree id="tree1" showRoot="false"  labelField="@NAME" width="100%" height="100%"

        • 1. Re: Tree dataSource as xml from webservice
          ergo_eleven Level 1

          It is useful to see the xml responce

          • 2. Re: Tree dataSource as xml from webservice
            bstroeb Level 1

            I found the issue. it's the namespace.  I just dont know how to reference the returned xml in the tree dataprovider because of the namespace.



            This is how the webservice returns the xml:


            <?xml version="1.0" encoding="utf-8"?>
            <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
                <get_tree_dataResponse xmlns="http://tempuri.org/">


            how do i handle the namespace and how do i set the dataprovider?

            • 3. Re: Tree dataSource as xml from webservice
              batmitra Level 1


              I use very much webservices in .net with flex but i gave up doing things like you are doing, i'm using a technic called DTO -Data transfer object, wich makes me do a little more code, mas in the end it pays off, here's what i do:


              1st - I make a class in .net where i put my fields as public attributes, this class has no constructor and nothing else , just the fields

              2nd- I build an array of classes and send it to flex as an object, this way my webservice put it clean as xml

              3rd-On flex i must have a class exactly the same as the one i created on point 1

              4th- i use an arraylist and fill it with the result of my calling to the webservice

              5th - If you make the tree dataprovider = to your arraylist is much better


              It helps too to look to a property on the tree control called root or somthing like that

              • 4. Re: Tree dataSource as xml from webservice
                LPVOID32 Level 1


                try to enhance you xml out put at the server side , using .Net xml serialization (http://www.devhood.com/Tutorials/tutorial_details.aspx?tutorial_id=236)


                .net service :

                create  userInfo class :

                public class UserInfo
                    [XmlAttribute("userName")]public string name;



                create user info collection class :


                public class UserList
                    // This attribute enables the ArrayList to be serialized:
                    // Explicitly tell the serializer to expect the Item class
                    // so it can be properly written to XML from the collection:
                    [System.Xml.Serialization.XmlArrayItem("userInfo", typeof(UserInfo))]
                    public ArrayList userColl;


                    public UserList()
                        userColl= new ArrayList();


                    public int AddUser(UserInfo uInfo)
                        return userColl.Add(uInfo);



                at client side:

                ArrayCollection userList

                userList.source =  e.result.userList.source;