A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: XMl questions

  1. #1
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    XMl questions

    I'm trying to work with some XML in flash.

    There are alot of nodes I don't need, but all the ones I do want are with attributes. Here's the XML. What I want are all the yweather nodes and their attributes. Any pointers?

    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    <rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
    <channel>
    <title>Yahoo! Weather - Marietta, GA</title>
    <link>http://us.rd.yahoo.com/dailynews/rss/weather/Marietta__GA/*http://xml.weather.yahoo.com/forecast/USGA0353_f.html</link>
    <description>Yahoo! Weather for Marietta, GA</description>
    <language>en-us</language>
    <lastBuildDate>Fri, 16 Dec 2005 1:55 pm EST</lastBuildDate>
    <ttl>60</ttl>
    <yweather:location city="Marietta" region="GA" country="US" />
    <yweather:units temperature="F" distance="mi" pressure="in" speed="mph" />
    <yweather:wind chill="39" direction="310" speed="10" />
    <yweather:atmosphere humidity="46" visibility="1127" pressure="30.10" rising="0" />
    <yweather:astronomy sunrise="7:37 am" sunset="5:31 pm" />
    <image>
    <title>Yahoo! Weather</title>
    <width>142</width>
    <height>18</height>
    <link>http://weather.yahoo.com/</link>
    <url>http://us.i1.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif</url>
    </image>
    <item>
    <title>Conditions for Marietta, GA at 1:55 pm EST</title>
    <geo:lat>33.96</geo:lat>
    <geo:long>-84.53</geo:long>
    <link>http://us.rd.yahoo.com/dailynews/rss/weather/Marietta__GA/*http://xml.weather.yahoo.com/forecast/USGA0353_f.html</link>
    <pubDate>Fri, 16 Dec 2005 1:55 pm EST</pubDate>
    <yweather:condition text="Mostly Cloudy" code="28" temp="45" date="Fri, 16 Dec 2005 1:55 pm EST" />
    <description><![CDATA[

    <img src="http://us.i1.yimg.com/us.yimg.com/i/us/we/52/28.gif" /><br />
    <b>Current Conditions:</b><br />
    Mostly Cloudy, 45 F<p />
    <b>Forecast:</b><BR />
    Fri - Mostly Cloudy. High: 46 Low: 32<br />
    Sat - Cloudy. High: 51 Low: 35<br />
    Sun - AM Rain. High: 48 Low: 32<br />
    <br />
    <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Marietta__GA/*http://xml.weather.yahoo.com/forecast/USGA0353_f.html">Full Forecast at Yahoo! Weather</a><BR/>
    (provided by The Weather Channel)<br/>
    ]]></description>
    <yweather:forecast day="Fri" date="16 Dec 2005" low="32" high="46" text="Mostly Cloudy" code="28" />
    <yweather:forecast day="Sat" date="17 Dec 2005" low="35" high="51" text="Cloudy" code="26" />
    <yweather:forecast day="Sun" date="18 Dec 2005" low="32" high="48" text="AM Rain" code="12" />
    <guid isPermaLink="false">USGA0353_2005_12_16_13_55_EST</guid>
    </item>
    </channel>
    </rss>
    <!-- p5.weather.dcn.yahoo.com uncompressed/chunked Fri Dec 16 11:22:27 PST 2005 -->

  2. #2
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    I pull it in using a backside xmlclass and bust the nodes just like it's an xml feed. That way you can filter the attributes and send them in. Give me a few...I can do better....


    Link removed ....

  3. #3
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Yikes! don't make me look bad man. LOL that was way too fast.

    Hey Chris what I'm trying to do is pull the yweather items into variables

    I've managed to drill down to the yweather nodes. But I don't think that they are using attributes.

    <yweather:location city="Marietta" region="GA" country="US" />

    What I'm going to try to do is make a cute graphic display of the data

    My test code so far
    PHP Code:
    weather=new XML();
    weather.ignoreWhite=true;
    weather.load("forecastrss.xml");

    weather.onLoad = function(success) {
        if (
    success) {
        
    processXML(weather);
        }
        }
        
    function 
    processXML(xmlDoc){
        
    total=xmldoc.firstChild.firstChild.childNodes.length
        
        
    for(a=0;a<total;a++){
            
    node=xmldoc.firstChild.firstChild.childNodes[a].toString()
            if (
    node.indexOf("yweather:")>0){
                
    txt1.text+=a.toString()+" "+node+node.childNodes[0]+' '+String.fromCharCode(13)+"__________________________________________"+String.fromCharCode(13)
                        
                }
            
            }
        } 

  4. #4
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    Thats the beauty. If you parse inside Flash, you get buggered by the CDATA. This way uses the class...strips the xml file for attributes you choose...creates variables and the array....manipulates them in the backside to create a customized string of text (can be anything man)......and sends them in as one string for a dynamic textfield with links intact if it's a linked attribute.

    If your interested I'll explain. If not...I'll shut up.

  5. #5
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    I had considered doing it that way. Keep talking.

    I got a little farther, I found localName is what location is in the following
    <yweather:location city="Marietta" region="GA" country="US" />
    but city etc are not attributes what are they?

  6. #6
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    Unless you are going to download that xml each day and make the yweather a fully tagged attribute it won't parse as a node. You need the CDATA (which is what I'm reading and sending in) that you can format using the created variable.

    So it ends up being a html enabled textfield is all you need. The formatting and all (coloring, etc) can be done with the backend for the field to read. You also get to read the weather live that way.

  7. #7
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Yeah I thought of that but I'm kinda bull headed when I get an idea in mind. I think I've got it now. Lots of code but it's gonna work. Would like to see that PHP code though.

  8. #8
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    LOL guess I'm wasting my time
    this is in the source of the page
    ************************** NOTICE *******************************
    The data (conditions, forecasts, news, images, logos) contained in
    this page are copyrighted by Yahoo! Canada Co. and the Weather Channel
    Enterprises, Inc. You are prohibited from using or repurposing this
    data in any way without express written consent from Yahoo! Canada Co. and
    the Weather Channel Enterprises, Inc.
    If you are looking for a source of weather data, please see the
    National Weather Service Website at http://www.nws.noaa.gov/. Their
    data is public information, to be used with appropriate
    byline/photo/image credits.
    ************************** NOTICE *******************************

  9. #9
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    It's in all of my RSS reader downloads. I made that xml of yours a file named "testfeed.xml" and placed it into the "blogdata" subfolder of the RSS package. Then make a copy of the "getfeed.php" file and save it as getfeed2.php.

    Change the POST it usually uses:

    $feedurl= $_POST["feedurl"];


    to a hard code to your testfeed file:

    $feedurl= "testfeed.xml";

    If you are going to hit that url live than use the full url to that feed instead.


    Save it and hit it in the browser. It sends out a variable named "txtMain"
    Play with the backside to get the attributes you want and construct the string how you want.


    Ideally, the best XML is xml you create. Anything else like this...was most likely created for php based feeders and never built with flash in mind so we have to make what we need. That yweather attribute was made for a purpose other than ours.

  10. #10
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    Hahaha....repurposed data....nice way of putting it. Guess I better smoke the demo....don't want to purposely repurpose.

  11. #11
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Bret, if you don't want to use php, try this
    Code:
    weather=new XML();
    weather.ignoreWhite=true;
    
    weather.onData = function(d){
     if (d != undefined){
      
      // convert xml data
      
      var xml_data = '';
      d = d.split('<yweather:');
      for (var i = 1; i < d.length; i++){
       d[i] = d[i].substr(0,d[i].indexOf('/>'));
       xml_data += '<' + d[i] + ' />';
      }
      this.parseXML(xml_data);
    
      // handle the converted xml data
    
      for (i = 0; i < this.childNodes.length; i++){
       
       var node_name = this.childNodes[i].nodeName;
       var node_attr = this.childNodes.attributes;
       
       txt1.text += '\nnodeName = ' + node_name + '\n';
       for (attr in node_attr){
        txt1.text += attr + " = " + node_attr[attr] + '\n';
       }
    
      }
    
     }
    }
    
    weather.load("forecastrss.xml");


    Edit:
    I should have read better. Now I submitted this I see you are not allowed to use it. What's the point of adding a rss button if you are not allowed to use it

    This one seems to be free but you may only fetch data once an hour so you still would have to use php to cache it on your server:
    http://www.rssweather.com/
    Last edited by w.brants; 12-17-2005 at 03:22 AM.

  12. #12
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Thanks Wilburt

  13. #13
    Can't Re- Member gusmus's Avatar
    Join Date
    Sep 2002
    Location
    España
    Posts
    663
    Blanius, the noaa updates are set to 24 hours unless there is a security warning (during winter hours) during summertine (hurricane season) you will have full 2 hour coverage and updates on any hot spot in the carribean/atlantic sector and Pacific / typhoon sector. Apart from that you will have basically zilch coverage (per satellite) Much better to get the radar for US or try this http://www.weather.com/maps/maptype/...=wxcenter_maps,, It's not a big deal,, but I'm a sailor from here and there and it all works for me, I rely on them sometimes. Cheers
    humanus somes est divinitus in ipsum
    Wiliiam Wallace

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center