|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome. |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
I'm working with a Yahoo weather XML feed, and I can't for the life of me figure out how to access the item I need.
Here is the XML file Code:
<?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 - Sunnyvale, CA</title> <link>http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/94089_f.html</link> <description>Yahoo! Weather for Sunnyvale, CA</description> <language>en-us</language> <lastBuildDate>Wed, 19 Mar 2008 12:27 pm PDT</lastBuildDate> <ttl>60</ttl> <yweather:location city="Sunnyvale" region="CA" country="US" /> <yweather:units temperature="F" distance="mi" pressure="in" speed="mph" /> <yweather:wind chill="59" direction="20" speed="8" /> <yweather:atmosphere humidity="67" visibility="1609" pressure="30.23" rising="0" /> <yweather:astronomy sunrise="7:12 am" sunset="7:20 pm" /> <image> <title>Yahoo! Weather</title> <width>142</width> <height>18</height> <link>http://weather.yahoo.com/</link> <url>http://l.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif</url> </image> <item> <title>Conditions for Sunnyvale, CA at 12:27 pm PDT</title> <geo:lat>37.39</geo:lat> <geo:long>-122.03</geo:long> <link>http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/94089_f.html</link> <pubDate>Wed, 19 Mar 2008 12:27 pm PDT</pubDate> <yweather:condition text="Partly Cloudy" code="30" temp="59" date="Wed, 19 Mar 2008 12:27 pm PDT" /> <description><![CDATA[ <img src="http://l.yimg.com/us.yimg.com/i/us/we/52/30.gif" /><br /> <b>Current Conditions:</b><br /> Partly Cloudy, 59 F<BR /><BR /> <b>Forecast:</b><BR /> Wed - Partly Cloudy. High: 61 Low: 45<br /> Thu - Sunny. High: 62 Low: 45<br /> <br /> <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/94089_f.html">Full Forecast at Yahoo! Weather</a><BR/> (provided by The Weather Channel)<br/> ]]></description> <yweather:forecast day="Wed" date="19 Mar 2008" low="45" high="61" text="Partly Cloudy" code="30" /> <yweather:forecast day="Thu" date="20 Mar 2008" low="45" high="62" text="Sunny" code="32" /> <guid isPermaLink="false">94089_2008_03_19_12_27_PDT</guid> </item> </channel> </rss><!-- p4.weather.sp1.yahoo.com compressed/chunked Wed Mar 19 12:51:32 PDT 2008 --> What I need is the text and temp pulled out of the yweather:condition item above. In my XSL document I can access everything fine using <xsl:value-of select="rss/channel/item/title" /> for example, but whenever I try and reference the yweather item, I don't know how to pull the attributes from inside it. I read about using the @ sign, so <xsl:value-of select="rss/channel/item/yweather:condition/@text" /> should work, but errors the application. I think it has something to do with references the item with a title such as this, yweather:condition Its got to be something small I'm missing. Any help???
__________________
-Jeremy | Arizona Search Engine Optimization and Web Programming Last edited by 4bidden; 03-19-2008 at 05:47 PM. |
|
|||
|
Quote:
EDIT: I found a fix from another web board. Here is what needed changed. I'm not familiar enough with this to know exactly why this was needed or what it did. 1. Change the yweather namespace declaration on your XSLT to xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" 2. Remove the rss namespace declaration on your XSLT, it's not necessary 3. Change your parameter's XPath to: rss/channel/item/yweather:condition/@text
__________________
-Jeremy | Arizona Search Engine Optimization and Web Programming |
|
|||
|
Hi 4bidden,
I am trying to do the same thing with teh Yahoo Weather feed but was not sure with your recommendations: Change the yweather namespace declaration on your XSLT to xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" 2. Remove the rss namespace declaration on your XSLT, it's not necessary 3. Change your parameter's XPath to: rss/channel/item/yweather:condition/@text I am using php 5, and can access item fine like this $xml = @file_get_contents("Yahoo! Weather - Allentown, PA"); $xml = new SimpleXMLElement($xml); $a = $xml->channel->item->title; But if I am trying to access the yweather:condition and put in $a = $xml->channel->item->yweather:condition->text I get errors on the : Thansk for any help! |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Trouble getting latest record for a given item | MOON | Database Discussion Forum | 1 | 11-07-2007 09:00 AM |
| MSN Item Search | EliteAF | MSN Search Discussion Forum | 1 | 08-14-2007 03:02 PM |
| Interesting item I found on ebay | countryjoe | The Castle Breakroom (General: Any Topic) | 0 | 11-10-2006 02:46 PM |
| Credit Card Processing for 1 item | saylor | eCommerce Discussion Forum | 2 | 01-12-2006 06:49 AM |
| MS Access 2000 issue | ADAM Web Design | IT Discussion Forum | 6 | 07-07-2005 01:08 AM |
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |