How to get the tag “” from Yahoo Weather RSS in PHP?

前端 未结 2 1465
臣服心动
臣服心动 2020-12-06 04:06
load(\'http://weather.yahooapis.com/forecastrss?p=VEXX0024&u=c\');
    $channel = $doc->getElementsByTagNa         


        
相关标签:
2条回答
  • 2020-12-06 04:20

    Something like:

    echo $itemgotten->getElementsByTagNameNS(
        "http://xml.weather.yahoo.com/ns/rss/1.0","condition")->item(0)->
         getAttribute("temp");
    

    The key is that you have to use getElementsByTagNameNS instead of getElementsByTagName and specify "http://xml.weather.yahoo.com/ns/rss/1.0" as the namespace.

    You know yweather is a shortcut for http://xml.weather.yahoo.com/ns/rss/1.0 because the XML file includes a xmls attribute:

    <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#">
    
    0 讨论(0)
  • 2020-12-06 04:29

    How about:

    • DOMElement::getAttribute — Returns value of attribute

    And if you need to get anything with namespaces, there is corresponding methods ending in NS.

    0 讨论(0)
提交回复
热议问题