5 Replies Latest reply on Oct 3, 2006 8:30 PM by dad_1953

    Parsing XML Data to add weather info to movie

    dad_1953
      Hello Everyone,
      I am trying to display weather information in my flash movie. I am having problems parsing the information that I receive. I can get the line of data from the xml date that is returned when I do an xml load. The problem is that I can’t parse the data. I have simplified by code to trouble shoot the problem. I am beginning to think that the line I get from the xml data is not the same as normal string data.

      When I run the “Examble 1” code I can pass the xml data to the ParseData function. When I trace the my_str (string) variable I see the data that I passed to the function and it looks correct. I then use the String.split method to pase the string into the my_array (array) variable. When I try to trace anything with my_array, the output is undefined. The trace(my_array.length) output is undefined

      When I run the same code (see “Example 2”) and create my own string that contains the text that I am pull out of the xml data and pass it to the ParseData function the trace(my_array.length) output is 14 as it should be.

      My question is what am I doing incorrectly?
      Why doesn’t the parsing work when I processing the xml text and it will work when I pass the same text as a string that I hard coded and assigned to a string variable?

      Note: the xml data that I am sending to the ParseData function is:

      Current Conditions - 69.2F / 20.7C | Clear - 8:29 PM PDT Oct. 1


      Thank you all in advance your help.
      Steve
        • 1. Re: Parsing XML Data
          The Feldkircher Level 2
          Hi

          I did a trace on the node of the rss feed you wish to Parse, this is a sample of what it returns

          <item><guid isPermaLink="false">1159773714</guid><title>Current Conditions - 65.2F / 18.4C | Scattered Clouds - 12:21 AM PDT Oct. 2</title><link> http://www.wunderground.com/US/CA/Baldwin_Park.html</link><description>Temperature: 65.2&amp;#176;F / 18.4&amp;#176;C | Humidity: 77% | Pressure: 29.93in / 1013.4hPa | Conditions: Scattered Clouds | Wind Direction: East | Wind Speed: 0.0mph / 0.0km/h</description><pubDate>Mon, 2 Oct 2006 00:21:00 PDT</pubDate></item>
          Current Conditions - 65.2F / 18.4C | Scattered Clouds - 12:21 AM PDT Oct. 2

          I think your problem is, your trying to Parse node tags and text. I think your best bet is to drill down further into this node and only extract the actual data you want ie: <title> or <description> nodes.

          Hope it helps

          • 2. Re: Parsing XML Data
            The Feldkircher Level 2
            Hi again

            I prefer using XPATH expressions to simplify the Parsing process, the following code drills down directly to all TITLE nodes.

            • 3. Re: Parsing XML Data
              dad_1953 Level 1
              I would like to thank “The Feldkircher” for his/her help. Using his/her example I was able to parse out all the information I need from the rss weather feed.

              Thank you again,
              Steve
              • 4. Re: Parsing XML Data
                The Feldkircher Level 2
                No Problem, Happy to help

                And just for the record its an he/him/it
                • 5. Re: Parsing XML Data
                  dad_1953 Level 1
                  I would like to give something back that will possible help someone else. I know that there are several people that have asked how to put weather information into their movies. Now that I have figured it out with the help of “The Feldkircher”; I would like to help someone else. I have created a very basic example (that works with flash version 8) to help point other people in the correct direction. I have striped out all the fluff to make the code easier to follow. The source of the data is from the following rss feed:

                  http://rss.wunderground.com/auto/rss_full/CA/Baldwin_Park.xml?units=english

                  an example of the text that will be parsed out is:

                  Temperature: 65.5&#176;F | Humidity: 64% | Pressure: 29.94in | Conditions: Clear | Wind Direction: WSW | Wind Speed: 3.0mph

                  The parsing code will parse and format the date so it looks like the following:

                  Irwindale Speedway Weather
                  Temperature: 65.5 °F
                  Humidity: 64%
                  Pressure: 29.94in
                  Conditions: Clear
                  Wind Speed: 3.0mph
                  Wind Direction: WSW


                  I hope this example will useful to other people
                  Steve