1 Reply Latest reply on May 9, 2013 12:28 PM by Peter Farland

    WebService response object in XML - parsing attributes


      Hi- new to Flex and I'm trying to parse out the attributes of the response object. I can get the entire object and see that its working, but I cant get just a single attribute. It pulls weather info for world cities. For example, I just want the location name and temperature.


      Any advice on this? Thanks!


      <?xml version="1.0"?>

      <!-- fds\rpc\RPCResultFaultMXML.mxml -->

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"




                  import mx.rpc.soap.SOAPFault;        

                  import mx.rpc.events.ResultEvent;

                  import mx.rpc.events.FaultEvent;

                  import mx.controls.Alert;

                  import mx.utils.ObjectUtil;


                  public function showErrorDialog(event:FaultEvent):void {

                      // Handle operation fault.

                      Alert.show(event.fault.faultString, "Error");


                  public function defaultFault(event:FaultEvent):void {

                      // Handle service fault.

                      if (event.fault is SOAPFault) {

                          var fault:SOAPFault=event.fault as SOAPFault;

                          var faultElement:XML=fault.element;

                          // You could use E4X to traverse the raw fault element returned in the SOAP envelope.

                          // ...


                      Alert.show(event.fault.faultString, "Error");              


                  public function log(event:ResultEvent):void {

                      // Handle result.




                      //var len:int;

                      //len = event.result.length;




                      //var myXML:XML = new XML(event.result);






          <mx:WebService id="WeatherService" wsdl="http://www.webservicex.com/globalweather.asmx?wsdl"


              <mx:operation name="GetWeather"










          <mx:TextInput id="myCity" text="Madrid"/>

          <mx:TextInput id="myCountry" text="Spain"/>

          <!-- Call the web service operation with a Button click. -->

          <mx:Button width="60" label="Get Weather"


          <!-- Display the Weather -->

          <mx:Label text="Weather:"/>

          <mx:TextArea text="{WeatherService.GetWeather.lastResult}" height="200"/>


        • 1. Re: WebService response object in XML - parsing attributes
          Peter Farland Level 3

          The WSDL says GetWeatherResponse is a string, and it appears to be a string of XML, so set <mx:operation resultFormat="object"> as this will unwrap the SOAP response value and leave a string typed value intact. You can then create a new ActionScript 3.0 E4X-based XML instance from the unwrapped string:


              var myXML:XML = new XML(event.result.toString());


          You can then travese the XML document using E4X syntax, a simple example is included below: