6 Replies Latest reply on Aug 31, 2009 7:07 AM by Gregory Lafrance

    HTTPService

    Yogi_ACE Level 2

      I want to add XML file as dataprovider to charting component. Data should be accessed using HTTP Service. Whenever I use HTTP Service instead of WebService it simply shows me result as "null"

      Can anybody share example or source?

        • 1. Re: HTTPService
          Barna Biro Level 3
          • 2. Re: HTTPService
            Madhav Subedi Level 4

            can you post your source code here?

            • 3. Re: HTTPService
              Yogi_ACE Level 2

              public function init():void{

                   var httpService:HTTPService = new HTTPService();

                   httpService.url = "data/Test.xml";

                   httpService.resultFormat = "e4x";

                   httpService.addEventListener(FaultEvent.FAULT, onFaultHttpService);

                   httpService.addEventListener(ResultEvent.RESULT, onResultHttpService);

                   httpService.send();

              }

               

              public function onResultHttpService(e:*):void{

                   viewXMLList = new XMLList(e.result);

                   chartDP  = xmlListToObjectArray(viewXMLList);

               

                   // chart data rendering...

                   chartObj.dataprovider = chartDP;

              }

               

               

              I also tryied with object conversion but it always returns null.

               

              public function xmlListToObjectArray(xmlList:XMLList):ArrayCollection

              {

                   var a:ArrayCollection = new ArrayCollection();

                   var attributes:XMLList = xmlList;

                   var o:Object = new Object();

                   for each (var attribute:XML in attributes)

                   {

                        var nodeName:String = attribute.name().toString();

                        var value:* = attribute;

                        o[nodeName] = value;

                   }

                   a.addItem(new ObjectProxy(o));

                   return a;

              }         

               

              • 4. Re: HTTPService
                Yogi_ACE Level 2

                Hi Barna,

                 

                I can retrieve the XML, I can also able to get the length but while type conversion it returns null.

                • 5. Re: HTTPService
                  Barna Biro Level 3

                  That might be because you are converting the result to the wrong type.

                   

                  viewXMLList = new XMLList(e.result);
                  

                   

                  Should be ( the correct type should be XML and not XMLList when you convert the result from the service ):

                   

                  var result:XML = XML(e.result);
                  

                   

                  See if that solves the problem ( once you have the XML structure, you can filter it for whatever data you need and convert those pieces into XMLList if you really want ).

                   

                  EDIT: Although, giving it a better thought, this should work as well: viewXMLList = new XMLList(e.result); ... Did you try checking the value of viewXMLList? If the value is correctly represented then the problem is somewhere else.

                  • 6. Re: HTTPService
                    Gregory Lafrance Level 6

                    Usually you need to go a little deeper into your data your result handler:

                     

                    public function onResultHttpService(e:*):void{

                        viewXMLList = new XMLList(e.result..item);

                     

                        chartDP  = xmlListToObjectArray(viewXMLList);

                     

                        // chart data rendering...

                        chartObj.dataprovider = chartDP;

                    }

                     

                    if your data was, for example:

                     

                    <data>

                        <item>

                            ... add elements for this item

                        </items>

                        <item>
                            ... add elements for this item
                        </items>

                        <item>
                            ... add elements for this item
                        </items>

                    </data>

                     

                    If this post answers your question or helps, please mark it as such.