2008年8月4日星期一

Re: [fw-core] Accessing namespaces xml/rss

Thank you sooo much. That helps.  I will see if I can figure out the different namespaces inside of the item tag on my own.

Thanks again.

-Cory

On Mon, Aug 4, 2008 at 11:23 AM, Pádraic Brady <padraic.brady@yahoo.com> wrote:
HI Kwylez,

Your problem is that the data for yweather elements is presented as attributes rather than text containing elements. Here's how to get the current weather condition (which is a "text" attribute on the "yweather:condition" element).

Zend_Feed::registerNamespace('yweather','http://xml.weather.yahoo.com/ns/rss/1.0');
Zend_Feed::registerNamespace('geo','http://www.w3.org/2003/01/geo/wgs84_pos#');
$feed = Zend_Feed::import('http://xml.weather.yahoo.com/forecastrss?p=EIXX0014&u=c');

$condition = $feed->current()->{'yweather:condition'};
$text = $condition->getDOM()->getAttribute('text');
var_dump($text);


Notice how I access attributes by falling back on DOMDocument/DOMElement methods after retrieving the DOM representation of the correct namespaced element? If you check the RSS form Yahoo are using getting any other data should be a simple copy of the last three lines above.

Hope this helps ;)

Paddy
 
Pádraic Brady

http://blog.astrumfutura.com
http://www.patternsforphp.com
OpenID Europe Foundation Member-Subscriber


----- Original Message ----
From: kwylez <kwylez@gmail.com>
To: fw-core@lists.zend.com
Sent: Monday, August 4, 2008 4:14:28 PM
Subject: [fw-core] Accessing namespaces xml/rss

I am trying to parse the Yahoo! rss weather feed, specifically their values inside of namespaces, but I can't find the right path to save my life. I have registered the namespaces, but can't find the right syntax. Suggestions? [code] weather->yweather->location->city}"; ?> weather->current()->description()?> weather->current()->geo->lat}"?> [/code] [xml] http://us.rd.yahoo.com/dailynews/rss/weather/Memphis__TN/*http://weather.yahoo.com/forecast/38105_f.html Yahoo! Weather for Memphis, TN en-us Mon, 04 Aug 2008 8:53 am CDT 60 142 18 http://weather.yahoo.com http://l.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif 35.05 -90 http://us.rd.yahoo.com/dailynews/rss/weather/Memphis__TN/*http://weather.yahoo.com/forecast/38105_f.html Mon, 04 Aug 2008 8:53 am CDT 38105_2008_08_04_8_53_CDT [/xml]

View this message in context: Accessing namespaces xml/rss
Sent from the Zend Core mailing list archive at Nabble.com.



--
Cory Wiles
kwylez@gmail.com
http://www.corywiles.com
http://www.400mtogo.com

没有评论: