3 Replies Latest reply on Oct 4, 2010 1:04 AM by Claudiu Ursica

    Read a single value from a XML

    napster3000

      This is my xml on remote server

       

       

      <results>
      <result><host><![CDATA[http://www.exampe.net/php.gp?ip={IP}&base_currency={CURRENCY}]]></host>
      <currency><![CDATA[USD]]></currency>
      <ip><![CDATA[79.125.106.126]]></ip>
      <city><![CDATA[Rome]]></city>
      <region><![CDATA[Latium]]></region>
      <areaCode><![CDATA[0]]></areaCode>
      <dmaCode><![CDATA[0]]></dmaCode>
      <countryCode><![CDATA[IT]]></countryCode>
      <countryName><![CDATA[Italy]]></countryName>
      <continentCode><![CDATA[EU]]></continentCode>
      <lat><![CDATA[41.8954656]]></lat>
      <lng><![CDATA[12.4823243]]></lng>
      <currencyCode><![CDATA[EUR]]></currencyCode>
      <currencySymbol><![CDATA[&#8364;]]></currencySymbol>
      <currencyConverter><![CDATA[0.7251105977]]></currencyConverter>
      <address><![CDATA[Rome Latium Italy]]></address>
      </result>
      </results>

       

       

       

       

      I've wrote this

       

      <s:HTTPService url="http://example.it/flex/api/myinfo.php" id="myinfoservice" />

       

       

      and i want to read a single value and diplay with function Alert.show()..

       

      for example the address value from xml

       

      How?

        • 1. Re: Read a single value from a XML
          Claudiu Ursica Level 4

          In your service result handler which I don't see in the code snippet but I

          assume you have for getting the xml from the server you do something like

           

          private function result(event:ResultEvent):void

          {

              var tmpResult:XML = (event.result as XML).result;

              var currency:String = tmpResult.currency.text();

              trace(currency);

          }

          • 2. Re: Read a single value from a XML
            napster3000 Level 1

            i, tried it but i don't see nothing...

             

            <fx:Declarations>

             

            <s:HTTPService url="http://preventivi-viaggi.it/flex/api/myinfo.php" id="MyInfoService"

               result="MyInfoService_resultHandler(event)"/>

             

             

            </fx:Declarations>

             

             

            protected function MyInfoService_resultHandler(event:ResultEvent):void

            {

            var tmpResult:XML = (event.result as XML).result;

            var address:String = tmpResult.address.text();

            Alert.show(address);

            }

            • 3. Re: Read a single value from a XML
              Claudiu Ursica Level 4

              Sorry man slight small mistake I was writing the code from my memory. The

              tmpResult produces actually and XMLList and not an XML.

               

               

               

              protected function MyInfoService_resultHandler(event:ResultEvent):void

              {

                              var tmpResult:XMLList = (event.result as XML).result;

                              var address:String = tmpResult.address.text();

                              Alert.show(address);

              }   

               

               

              And you need to set the  resultFormat to "e4x" from for your service otherwise

              the result will be wrapper inside an ObjectProxy.

               

               

              <s:HTTPService

                          url="http://preventivi-viaggi.it/flex/api/myinfo.php"

                          id="MyInfoService"

                          resultFormat="e4x"

                          result="MyInfoService_resultHandler(event)"/>

               

              C