8 Replies Latest reply on May 9, 2009 8:34 AM by 3rdshiftcoder

    webservices - formatting xml

    3rdshiftcoder

      hi-

       

      below is my code sample. i can return a response from webservice to my text field but i cant filter out the parts i dont need.

       

      this is what it returns. as you will see with my code below i cant filter what i need.

      thanks for any assistance on how i can filter that data.

       

      3rdshiftcoder

       

      <GetWeatherByZipCodeResponse xmlns="http://www.webservicex.net" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <GetWeatherByZipCodeResult>
          <Latitude>33.3291245</Latitude>
          <Longitude>111.9943</Longitude>
          <AllocationFactor>0.008745</AllocationFactor>
          <FipsCode>04</FipsCode>
          <PlaceName>PHOENIX</PlaceName>
          <StateCode>AZ</StateCode>
          <Details>
            <WeatherData>
              <Day>Saturday, May 09, 2009</Day>
              <WeatherImage>http://forecast.weather.gov/images/wtf/few.jpg</WeatherImage>
              <MaxTemperatureF>103</MaxTemperatureF>
              <MinTemperatureF>70</MinTemperatureF>
              <MaxTemperatureC>39</MaxTemperatureC>
              <MinTemperatureC>21</MinTemperatureC>
            </WeatherData>
            <WeatherData>
              <Day>Sunday, May 10, 2009</Day>
              <WeatherImage>http://forecast.weather.gov/images/wtf/few.jpg</WeatherImage>
              <MaxTemperatureF>101</MaxTemperatureF>
              <MinTemperatureF>67</MinTemperatureF>
              <MaxTemperatureC>38</MaxTemperatureC>
              <MinTemperatureC>19</MinTemperatureC>
            </WeatherData>

      etc...

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute"
      creationComplete="userRequest.GetWeatherByZipCode()">
      <mx:WebService id="userRequest"
              wsdl="http://www.webservicex.net/WeatherForecast.asmx?wsdl"
              useProxy="false">
              <mx:operation name="GetWeatherByZipCode" resultFormat="e4x"
              fault="mx.controls.Alert.show(event.fault.faultString)"
              result="remotingCFCHandler(event)">
                  <mx:request>
                      <ZipCode>85044</ZipCode>
                  </mx:request>
              </mx:operation>
          </mx:WebService>
      <mx:Form x="22" y="10" width="493">
      <mx:HBox>
      <mx:Label text="zipcode"/>
      <mx:TextInput id="zipcode" width="300" height="500" />
      </mx:HBox>
      <mx:Button label="Submit" click="clickHandler()"/>
      </mx:Form>
      <!--<mx:DataGrid id="dgUserRequest" x="22" y="128">
      <mx:columns>
      <mx:DataGridColumn headerText="zipcode" dataField="zipcode1"/>
      <mx:DataGridColumn headerText="User Name" dataField="USERNAME"/>
      </mx:columns>
      </mx:DataGrid>-->
         
      <mx:Script>
      <![CDATA[
      import mx.rpc.events.ResultEvent;

       

      [Bindable] public var xmlResults:XML;
      [Bindable] public var a:XMLList;

       

                 
      private function remotingCFCHandler(e:ResultEvent):void
      {
      //dgUserRequest.dataProvider = e.result;
      zipcode.text = e.result.toString();  // returns document response found above
      xmlResults= new XML(zipcode.text);
      xmlResults.ignoreWhite = true;

       

      var listResults:XMLList;
      // listResults = xmlResults.GetWeatherByZipCodeResponse.GetWeatherByZipCodeResult.Details.WeatherData.Day;
      // zipcode.text = "{ 'a': + listResults}";

       

      //    ???? the above 2 commented lines dont filter my results. i thought those 2 lines would work.

       


      }
      private function clickHandler():void
      {
         userRequest.GetWeatherByZipCode();
      }
      ]]>
      </mx:Script>
      </mx:Application>

        • 1. Re: webservices - formatting xml
          Gregory Lafrance Level 6

          Have you confirmed you are getting data back? What exactly do you want to see after you filter? Your code indicates you want to see the day, but you are putting it in a variable called zipcode.

          • 2. Re: webservices - formatting xml
            3rdshiftcoder Level 1

            hi -

            zipcode is the id for the textinput control.

             

            zipcode.text = e.result.toString();

             

            this line above returns data from the response but it is the entire data and not filtered.

            ------------------------------------------------------------------------------------------ ------------------------------------------------------------------


            xmlResults= new XML(zipcode.text);
            //xmlResults.ignoreWhite = true;

             

            here i am trying to add the data returned in the text control to an xml variable.

            ------------------------------------------------------------------------------------------ -------------------------------------------------------------

             

            var listResults:XMLList;
            listResults = xmlResults.GetWeatherByZipCodeResponse.GetWeatherByZipCodeResult.Details.WeatherData.Day;
            zipcode.text = "{ 'a': + listResults}";

             

            and this is where i get lost totally. i thought that this would filter my data and place the filtered data

            into the textinput control with id of zipcode.

             

            thanks for replying-

            3rdshiftcoder

            • 3. Re: webservices - formatting xml
              Gregory Lafrance Level 6

              But what do you mean when you say you are trying to filter, and what are you trying to see from your data. Are you trying to see data for certain dates?

               

              <WeatherData>
                      <Day>Saturday, May 09, 2009</Day>
                      <WeatherImage>http://forecast.weather.gov/images/wtf/few.jpg</WeatherImage>
                      <MaxTemperatureF>103</MaxTemperatureF>
                      <MinTemperatureF>70</MinTemperatureF>
                      <MaxTemperatureC>39</MaxTemperatureC>
                      <MinTemperatureC>21</MinTemperatureC>
                    </WeatherData>

              1 person found this helpful
              • 4. Re: webservices - formatting xml
                3rdshiftcoder Level 1

                Hi Greg-

                 

                Exactly! except i dont really care about dates. i am more interested in the temperatures.

                I just used that as an example.

                 

                Here is the link that explains about filtering e4x.

                 

                http://dispatchevent.org/roger/as3-e4x-rundown/

                 

                below is a quote from this link and it describes an expression with filters.

                 

                " These are the basics of E4X. You’ve probably figured these ones out already cuz you is a pimp!

                thePeople.person.age

                Use dot syntax to select child nodes by name. The variable is already associated with the root node so there’s no need to write <people> into the expression. The expression above has two successive filters. The first one gets you all the <person> nodes  immediately below the root node, in other words, an XMLList. The second one gets you all the <age> nodes below all the nodes in the first filter. Result:

                <age>27</age>
                <age>26</age>

                Again, this is an XMLList, and notice how it retrieves all the age nodes under all the person nodes.

                 

                "

                i want to access WeatherData and retrieve the temperature values.

                 

                a node <MaxTemperatureF>103</MaxTemperatureF> is one i may wish to get the value of.

                the value for this node i'd like to return is 103.

                • 5. Re: webservices - formatting xml
                  3rdshiftcoder Level 1

                  i cant figure out when i leave these lines commented out i can get data.

                  but when i apply the filter, i get

                   

                  { 'a': + listResults}

                  verbatim

                   

                  now if i was to comment the following 3 lines this is what the data looks like

                  in the textinput control.

                   

                  //var listResults:XMLList;
                  //listResults = xmlResults.GetWeatherByZipCodeResult.Details.WeatherData.MaxTemperatureF;
                  //zipcode.text = listResults;

                   

                  data returned to textinput control with 3 lines commented out is below:

                   

                  <GetWeatherByZipCodeResponse xmlns="http://www.webservicex.net" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                    <GetWeatherByZipCodeResult>
                      <Latitude>33.3291245</Latitude>
                      <Longitude>111.9943</Longitude>
                      <AllocationFactor>0.008745</AllocationFactor>
                      <FipsCode>04</FipsCode>
                      <PlaceName>PHOENIX</PlaceName>
                      <StateCode>AZ</StateCode>
                      <Details>
                        <WeatherData>
                          <Day>Saturday, May 09, 2009</Day>
                          <WeatherImage>http://forecast.weather.gov/images/wtf/few.jpg</WeatherImage>
                          <MaxTemperatureF>103</MaxTemperatureF>
                          <MinTemperatureF>70</MinTemperatureF>
                          <MaxTemperatureC>39</MaxTemperatureC>
                          <MinTemperatureC>21</MinTemperatureC>
                        </WeatherData>
                        <WeatherData>
                          <Day>Sunday, May 10, 2009</Day>
                          <WeatherImage>http://forecast.weather.gov/images/wtf/few.jpg</WeatherImage>
                          <MaxTemperatureF>101</MaxTemperatureF>
                          <MinTemperatureF>67</MinTemperatureF>
                          <MaxTemperatureC>38</MaxTemperatureC>
                          <MinTemperatureC>19</MinTemperatureC>
                        </WeatherData>
                        <WeatherData>
                          <Day>Monday, May 11, 2009</Day>
                          <WeatherImage>http://forecast.weather.gov/images/wtf/few.jpg</WeatherImage>
                          <MaxTemperatureF>102</MaxTemperatureF>
                          <MinTemperatureF>68</MinTemperatureF>
                          <MaxTemperatureC>39</MaxTemperatureC>
                          <MinTemperatureC>20</MinTemperatureC>
                        </WeatherData>
                        <WeatherData>
                          <Day>Tuesday, May 12, 2009</Day>
                          <WeatherImage>http://forecast.weather.gov/images/wtf/few.jpg</WeatherImage>
                          <MaxTemperatureF>102</MaxTemperatureF>
                          <MinTemperatureF>69</MinTemperatureF>
                          <MaxTemperatureC>39</MaxTemperatureC>
                          <MinTemperatureC>21</MinTemperatureC>
                        </WeatherData>
                        <WeatherData>
                          <Day>Wednesday, May 13, 2009</Day>
                          <WeatherImage>http://forecast.weather.gov/images/wtf/few.jpg</WeatherImage>
                          <MaxTemperatureF>100</MaxTemperatureF>
                          <MinTemperatureF>68</MinTemperatureF>
                          <MaxTemperatureC>38</MaxTemperatureC>
                          <MinTemperatureC>20</MinTemperatureC>
                        </WeatherData>
                        <WeatherData>
                          <Day>Thursday, May 14, 2009</Day>
                          <WeatherImage>http://forecast.weather.gov/images/wtf/few.jpg</WeatherImage>
                          <MaxTemperatureF>100</MaxTemperatureF>
                          <MinTemperatureF>68</MinTemperatureF>
                          <MaxTemperatureC>38</MaxTemperatureC>
                          <MinTemperatureC>20</MinTemperatureC>
                        </WeatherData>
                        <WeatherData>
                          <Day>Friday, May 15, 2009</Day>
                          <WeatherImage>http://forecast.weather.gov/images/wtf/few.jpg</WeatherImage>
                          <MaxTemperatureF>101</MaxTemperatureF>
                          <MinTemperatureF>67</MinTemperatureF>
                          <MaxTemperatureC>38</MaxTemperatureC>
                          <MinTemperatureC>19</MinTemperatureC>
                        </WeatherData>
                      </Details>
                    </GetWeatherByZipCodeResult>
                  </GetWeatherByZipCodeResponse>

                  • 6. Re: webservices - formatting xml
                    3rdshiftcoder Level 1

                    var listResults:XMLList
                    listResults = thePeople.person.age;
                    zipcode.text = listResults;

                     

                    textfield values:

                    <age>27</age>
                    <age>26</age>

                    • 7. Re: webservices - formatting xml
                      3rdshiftcoder Level 1

                      my last post just went crazy on me.

                      dont try to understand it.  sorry.

                       

                      This code sample works and the other code didnt. Invalid xml object?

                      I am loopy enough without this going on.

                       

                      var thePeople:XML = <people>
                          <person name="Mims Wright" suffix="III">
                              <age>27</age>
                              <aka>Mims H Wright</aka>
                              <aka>Teh AWesoeomes!</aka>
                          </person>
                          <person name="Roger Braunstein">
                              <age>26</age>
                              <aka>Rog</aka>
                              <aka>That guy</aka>
                          </person>
                      </people>;

                       

                       

                       

                      trace(thePeople.person.age);

                       

                      var listResults:XMLList;
                      listResults = thePeople.person.age;
                      zipcode.text = listResults;

                       

                      results printed:

                      <age>27</age>
                      <age>26</age>

                      • 8. Re: webservices - formatting xml
                        3rdshiftcoder Level 1

                        hi-

                         

                        i can fix this now. i will have to delete that lattitude, longitude etc. data at the top

                        of my textinput control to make it a valid xml object so i can filter.

                         

                        i can use mystr (a String object) and clean it up with some methods.

                        this was very easy compared to my last attempt at doing this some

                        time ago with php.

                         

                        thanks for answering.

                         

                        3rdshiftcoder