2 Replies Latest reply on Jul 16, 2007 12:50 PM by pault107

    HTTPService/XML issue

    pault107
      Hey fellow Flexers

      I'm a relative newb to Flex so there is probably a simple solution to my issue, but I've been trying to fix this for hours now with no success.

      I'm loading in some XML using HTTPService and accessing the parameters without any issue, it's the node value I have issues with.

      The XML is in the following format:

      <events>
      <comment up="1">Some text goes here 1</comment>
      <comment up="3">Some text goes here 2</comment>
      </events>

      Now, with my current code I can access the 'up' parameter, but I can't seem to get to the actual node value. i.e "Some text goes here.."

      My code:

      <mx:HTTPService id="dataRequest" url=myURL/>

      <mx:Panel>

      <mx:DataGrid dataProvider="{dataRequest.lastResult.events.comment}">

      <mx:columns>

      <mx:DataGridColumn headerText="Title" dataField="comment"/> <<**this line is the issue**
      <mx:DataGridColumn headerText="Up" dataField="up"/> << this line works fine

      </mx:columns>

      </mx:DataGrid>
      <mx:Panel>

      I've chopped out some of the code to make it readable. I know that the code is incorrect but I've tried dozens of variations to get it working but I'm having no joy.

      Any ideas?

      Thanks in advance.

      Paul
        • 1. Re: HTTPService/XML issue
          ntsiii Level 3
          Suggestions:
          1) Use resultFormat="e4x" on the HTTPService tag. The default is object, which causes Flex to convert the xml into a nested object structure. God only knows the result of that.
          2) Do not bind to the result. Use a result handler, so you can debug the data.

          Here are some code snippets below.
          Tracy
          Sample code using HTTPService, e4x, handler function to populate a list item.
          Also shows usage of AsyncToken.

          The DataGrid tag:
          <mx:DataGrid id="dg" dataProvider="{_xlcMyListData}" .../>


          The HTTPService tag:
          <mx:HTTPService id="service" resultFormat="e4x" result="onResult(event)" fault="..../>

          Script block declaration:
          import mx.rpc.Events.ResultEvent;
          [Bindable]private var _xlcMyListData:XMLListCollection;

          Invoke send:
          var oRequest:Object = new Object();
          oRequest.Arg1 = "value1";
          var callToken:AsyncToken = service.send(oRequest);
          token.callId = "myQuery1";

          Result Handler function:
          private function onResult(oEvent:ResultEvent):void {
          var xmlResult:XML = XML(event.result); //converts result Object to XML. can also use "as" operator
          var xlMyListData:XMLList = xmlResult.myListData; //depends on xml format, is row data
          _xlcMyListData = new XMLListCollection(xlMyListData); //wrap the XMLList in a collection
          trace(_xlcMyListData.toXMLString()); //so you can see exactly how to specify dataField or build labelFunction
          var callToken:AsyncToken = oEvent.token;
          var sCallId = callToken.callId; //"myQuery1"
          switch(sCallId) {
          case "myQuery1":
          doQuery2();
          break;
          ...
          }
          }//onResult
          • 2. Re: HTTPService/XML issue
            pault107 Level 1
            Thanks for your help ntsiii. I actually fixed the problem by changing this line:


            <mx:DataGridColumn headerText="Title" dataField="comment"/>

            to:


            <mx:DataGridColumn headerText="Title" dataField="value"/>

            Your method looks like it will be much more scalable in future though - so I will look into it.

            Thanks once again.

            Paul