4 Replies Latest reply on Feb 1, 2007 11:19 AM by peterent

    XML and HTTPSERVICE

    187_2007 Level 1
      I am receiving the XML file back... Trying to bind it to my Tree... and it displays nothing.. Is the problem when I am receiving the result back from the HTTPService I am trying to put it into an XML variable? I donno... What is wrong with my syntex?

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
      xmlns:v="views.*" backgroundColor="black" borderStyle="inset" cornerRadius="0" viewSourceURL="srcview/index.html"
      backgroundGradientColors="[#ffffff, #b4d2ec]" creationComplete="init();">

      <mx:Script>
      <![CDATA[
      import mx.collections.XMLListCollection;
      import mx.rpc.events.ResultEvent;
      import mx.collections.ArrayCollection;

      [Bindable]
      private var DataTree:XML;

      private function init():void{
      e4xService.send();
      }

      private function resultHandler(event:ResultEvent):void
      {
      var DataTree:XML = XML(event.result);
      }
      ]]>
      </mx:Script>

      <mx:HTTPService id="e4xService"
      url=" http://www.franticphotos.com/0personal0/flex/CFC/Tree.xml"
      result="resultHandler(event)" resultFormat="e4x"/>


      <mx:HBox width="100%" height="100%"
      paddingLeft="10"
      paddingRight="10"
      paddingTop="10"
      paddingBottom="10">
      <mx:Panel width="250" height="100%" layout="absolute" paddingLeft="10" paddingRight="10" paddingTop="10" paddingBottom="10" borderColor="#666666" backgroundColor="#efefef" title="EyeWonder Site Spec System">

      <mx:Tree id="myTree" x="10" y="10" width="210" dataProvider="{DataTree}" labelField="@label" height="697" />

      </mx:Panel>
      <mx:Canvas width="100%" height="100%" backgroundColor="#ffffff" id="canvas1" />

      </mx:HBox>

      </mx:Application>
        • 1. Re: XML and HTTPSERVICE
          peterent Level 2
          What's your XML look like? The Tree expects it to be very uniform and you should use an XMLListCollection and not just XML. If your XML is not uniform (that is, all elements have the same node name), you'll need a labelFunction on the Tree to extract the correct information.

          You can check my blog - I wrote a couple of articles about XML and the Tree control. But post a sample of your XML here and we'll figure it out.
          • 2. Re: XML and HTTPSERVICE
            187_2007 Level 1
            Here is my XML..

            http://www.franticphotos.com/0personal0/flex/CFC/Tree.xml

            I will try your suggestion as well. I'll be online watching the thread.
            • 3. XML and HTTPSERVICE
              187_2007 Level 1
              HA. I figured it out... It's much easier to use the Tag version of XMLListCollection. Here is my code. The URL above is still valid.


              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
              xmlns:v="views.*" backgroundColor="black" borderStyle="inset" cornerRadius="0" viewSourceURL="srcview/index.html"
              backgroundGradientColors="[#ffffff, #b4d2ec]" creationComplete="init();">

              <mx:Script>
              <![CDATA[

              private function init():void{
              e4xService.send();
              }
              ]]>
              </mx:Script>

              <mx:HTTPService id="e4xService" url=" http://www.franticphotos.com/0personal0/flex/CFC/Tree.xml" resultFormat="e4x"/>

              <mx:XMLListCollection id="theXMLList" source="{e4xService.lastResult.Mainparent}" />

              <mx:HBox width="100%" height="100%"
              paddingLeft="10"
              paddingRight="10"
              paddingTop="10"
              paddingBottom="10">

              <mx:Panel width="250" height="100%" layout="absolute" paddingLeft="10" paddingRight="10" paddingTop="10" paddingBottom="10" borderColor="#666666" backgroundColor="#efefef" title="EyeWonder Site Spec System">

              <mx:Tree id="myTree" x="10" y="10" width="210" dataProvider="{theXMLList}" labelField="@label" height="697" />

              </mx:Panel>
              <mx:Canvas width="100%" height="100%" backgroundColor="#ffffff" id="canvas1" />

              </mx:HBox>

              </mx:Application>
              • 4. Re: XML and HTTPSERVICE
                peterent Level 2
                Glad that worked out for you.