;

PDA

Click to See Complete Forum and Search --> : XMl questions


blanius
12-16-2005, 09:17 PM
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 -->

Chris_Seahorn
12-16-2005, 10:47 PM
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 ....

blanius
12-16-2005, 10:52 PM
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

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.leng th

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)

}

}
}

Chris_Seahorn
12-16-2005, 11:08 PM
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.

blanius
12-16-2005, 11:17 PM
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?

Chris_Seahorn
12-16-2005, 11:22 PM
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.

blanius
12-16-2005, 11:43 PM
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.

blanius
12-16-2005, 11:53 PM
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 *******************************

Chris_Seahorn
12-16-2005, 11:54 PM
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.

Chris_Seahorn
12-17-2005, 12:00 AM
Hahaha....repurposed data....nice way of putting it. Guess I better smoke the demo....don't want to purposely repurpose. :p

w.brants
12-17-2005, 02:38 AM
Bret, if you don't want to use php, try this
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 = 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[i].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 :confused:

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/

blanius
12-17-2005, 09:37 AM
Thanks Wilburt

gusmus
12-18-2005, 01:12 PM
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/dopplerradarusnational/index_large.html?from=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