0

I am developing a weather forecast of the current weather and weather forecast for my schools website. For this I will be using Yahoos RSS weather forecast. In this XML file there are some values stored in attributes. I would like to get those out with PHP. The file can be found here: http://weather.yahooapis.com/forecastrss?w=12602818&u=c

The XML file states the folowing line:

<rss xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0">

The value I would like to get out is the following:

<yweather:condition text="Partly Cloudy" code="30" temp="22" date="Wed, 12 Jun 2013 4:20 pm CEST"/>

I would, for example, like to receive 'temp' from this yweather:condition. Can anybody instruct me how this could be done with PHP?

  • using an XML parser - there are many for PHP – pulsar Jun 12 '13 at 15:11
  • please post an instructive and valid part of the XML within your question (use edit). Thank you! – michi Jun 12 '13 at 16:12
  • Please use the search. If we haven't this even answered specific to yahoo weather RSS, then at least it's answered with xml-namespaces in general. See [Parsing Yahoo weather RSS feed to get namespaced city element](http://stackoverflow.com/questions/14095012/parsing-yahoo-weather-rss-feed-to-get-namespaced-city-element?rq=1) and others from the related column on the right --> – hakre Jun 13 '13 at 08:54

1 Answers1

1
<?php
$doc = new DOMDocument();
$doc->load('http://weather.yahooapis.com/forecastrss?w=12602818&u=c');
$channel = $doc->getElementsByTagName("channel");
foreach($channel as $chnl){
    $item = $chnl->getElementsByTagName("item");
    foreach($item as $itemgotten){
        $curtemp = $itemgotten->getElementsByTagNameNS("http://xml.weather.yahoo.com/ns/rss/1.0","condition")->item(0)->getAttribute("temp");
        echo $curtemp;
    }
}
?>

this fixed the issue! Answer found here: How to get the tag "<yweather:condition>" from Yahoo Weather RSS in PHP?

Community
  • 1
  • 1