1 Reply Latest reply on Apr 13, 2009 11:30 AM by Brent Lamborn

    How to get webservice data to show in tree?

    bstroeb

      I have a webservice that returns an xml document. i cant get it to display in the tree the right way.  here's my code:

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
          <mx:Script>
              <![CDATA[
                  import mx.rpc.events.ResultEvent;
                  import mx.collections.XMLListCollection;
                  default xml namespace = "http://tempuri.org/";
                 
                  [Bindable]
                  private var mydata:XMLListCollection = new XMLListCollection();
                 
                  private function resultTree(event:ResultEvent):void{
                      mydata.source = new XMLList(new XML(event.result[0]));               
                  }
              ]]>
          </mx:Script>

       

          <mx:WebService id="ws1" wsdl="http://129.81.119.89:8081/service1.asmx?WSDL"
              showBusyCursor="true" useProxy="false">
              <mx:operation name="HelloWorld" result="resultTree(event)" resultFormat="e4x" />
          </mx:WebService>

       

          <mx:Tree id="tree1"
              initialize="ws1.HelloWorld.send()"
              dataProvider="{mydata}"
              labelField="@label"
              height="500" width="500">
          </mx:Tree>
         
      </mx:Application>

       

       

      here's the returned data

      <HelloWorldResponse xmlns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <HelloWorldResult>
          <root label="Home Node">
            <node1 label="Parent 1">
              <node2 label="Child 1"/>
            </node1>
            <node1 label="Parent 2">
              <node2 label="Child 1"/>
            </node1>
          </root>
        </HelloWorldResult>
      </HelloWorldResponse>

       

      Here's what the tree looks like (notice the first 3 nodes are showing the entire xml and the last 2 nodes are exactly what i want to show):

      tree_problem.jpg

       


      I think i have all the right code but am not sure how to assign the mydata variable the correct output from the service.  Am I handling the namspace correctly?

        • 1. Re: How to get webservice data to show in tree?
          Brent Lamborn Level 2

          I wouldnt use an XMLListCollection. I'd just make it XML. Like this:

           

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">
               <mx:Script>
                    <![CDATA[
                         [Bindable]var hello:XML = <HelloWorldResult><root label="Home Node"><node1 label="Parent 1"><node2 label="Child 1"/></node1><node1 label="Parent 2"><node2 label="Child 1"/></node1></root></HelloWorldResult>
                    ]]>
               </mx:Script>
               
                <mx:Tree id="tree1" 
                  dataProvider="{hello.children()}"
                  labelField="@label"
                  height="500" width="500">
              </mx:Tree>
              
          </mx:Application>