WebService XML Parsing


hi,

 

i trying parse xml returned webservice http://ws.cdyne.com/weatherws/weather.asmx?wsdl . need information in city tag. not sure wrong here. not sure how city xml returned webservice. if returnedxml.*; prints whole xml returned service, how retrieve city?

 

thanks help.

 

here code:

 

<?xml version="1.0" encoding="utf-8"?>
<mx:application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalalign="middle"
        backgroundcolor="white"
        initialize="onload()">

 

    <mx:script>
        <![cdata[
            import mx.controls.alert;
            import mx.rpc.events.resultevent;
            import mx.rpc.events.faultevent;
            import mx.utils.objectutil;

 

            private var returnxml:xml;
           
            private function onload():void {
                webservice.getcityforecastbyzip.send();
            }

 

            private function getcityforecastbyzip_result(evt:resultevent):void {
               returnxml = new xml(evt.result);
               textarea.text =returnxml.*;
            }

 

            private function getcityforecastbyzip_fault(event:faultevent):void {
                alert.show(event.fault.faultcode + ": " + event.fault.faultstring, "error");
            }

 


        ]]>
    </mx:script>

 

    <mx:webservice id="webservice" wsdl="http://ws.cdyne.com/weatherws/weather.asmx?wsdl">
        <mx:operation name="getcityforecastbyzip" resultformat="e4x" result="getcityforecastbyzip_result(event);" fault="getcityforecastbyzip_fault(event);">
            <mx:request>
                <zip>07310</zip>
            </mx:request>
        </mx:operation>
       
    </mx:webservice>

 

    <mx:textarea id="textarea"
            editable="false"
            width="100%"
            height="100%" />

 

</mx:application>

 

 

here webservice if print returnxml.*

 

<getcityforecastbyzipresult xmlns="http://ws.cdyne.com/weatherws/">
  <success>true</success>
  <responsetext>city found</responsetext>
  <state>nj</state>
  <city>jersey city</city>
  <weatherstationcity>newark</weatherstationcity>
  <forecastresult>
    <forecast>
      <date>2009-06-05t00:00:00</date>
      <weatherid>5</weatherid>
      <desciption>rain</desciption>
      <temperatures>
        <morninglow/>
        <daytimehigh>62</daytimehigh>
      </temperatures>
      <probabilityofprecipiation>
        <nighttime/>
        <daytime/>
      </probabilityofprecipiation>
    </forecast>
    <forecast>
      <date>2009-06-06t00:00:00</date>
      <weatherid>4</weatherid>
      <desciption>sunny</desciption>
      <temperatures>
        <morninglow>55</morninglow>
        <daytimehigh>81</daytimehigh>
      </temperatures>
      <probabilityofprecipiation>
        <nighttime/>
        <daytime/>
      </probabilityofprecipiation>
    </forecast>

</forecastresult>
</getcityforecastbyzipresult>

i changed resultformat e4x xml.

 

here code working:

 

<?xml version="1.0" encoding="utf-8"?>
<mx:application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalalign="middle"
        backgroundcolor="white"
        initialize="onload()">

 

    <mx:script>
        <![cdata[
            import mx.controls.alert;
            import mx.rpc.events.resultevent;
            import mx.rpc.events.faultevent;
            import mx.utils.objectutil;

 

            private var returnxml:xml;
            private namespace weather = "http://ws.cdyne.com/weatherws/";
            use namespace weather;
  
            private function onload():void {
                webservice.getcityforecastbyzip.send();
            }

 

            private function getcityforecastbyzip_result(evt:resultevent):void {
               returnxml = new xml(evt.result);
               textarea.text ="result "+returnxml.getcityforecastbyzipresult.city;
            }

 

            private function getcityforecastbyzip_fault(event:faultevent):void {
                alert.show(event.fault.faultcode + ": " + event.fault.faultstring, "error");
            }

 


        ]]>
    </mx:script>

 

    <mx:webservice id="webservice" wsdl="http://ws.cdyne.com/weatherws/weather.asmx?wsdl">
        <mx:operation name="getcityforecastbyzip" resultformat="xml" result="getcityforecastbyzip_result(event);" fault="getcityforecastbyzip_fault(event);">
            <mx:request>
                <zip>07310</zip>
            </mx:request>
        </mx:operation>
       
    </mx:webservice>

 

    <mx:textarea id="textarea"
            editable="false"
            width="100%"
            height="100%" />

 

</mx:application>

 

thanks



More discussions in Flex (Read Only)


adobe

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

RFID-RC522 with Arduino Pro Micro project. Error on the code?