本文介绍了如何获得标签“< yweather:condition>".从Yahoo Weather RSS in PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

<?php
    $doc = new DOMDocument();
    $doc->load('http://weather.yahooapis.com/forecastrss?p=VEXX0024&u=c');
    $channel = $doc->getElementsByTagName("channel");
    foreach($channel as $chnl)
    {
        $item = $chnl->getElementsByTagName("item");
        foreach($item as $itemgotten)
        {
            $describe = $itemgotten->getElementsByTagName("description");
            $description = $describe->item(0)->nodeValue;
            echo $description;
        }
    }
?>

您将看到一个简单的脚本,该脚本从上述url返回标签的内容.关键是我不需要那种内容,我需要标签里面的那个.我需要属性 code temp 文本.我如何用我的实际代码这么简单?谢谢

And as you can see is a simple script who return the content of the tag from the above url. The thing is that i dont need that content, i need the one who is inside the tag . I need the attributes code, temp, text. How do i do that simple with my actual code? Thanks

标签内容的示例:

<yweather:condition  text="Partly Cloudy"  code="30"  temp="30"  date="Fri, 16 Jul 2010 8:30 am AST" />

推荐答案

类似的东西

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

关键是您必须使用getElementsByTagNameNS而不是getElementsByTagName并指定"http://xml.weather.yahoo.com/ns/rss/1.0"作为命名空间.

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.

您知道yweatherhttp://xml.weather.yahoo.com/ns/rss/1.0的快捷方式,因为XML文件包含xmls属性:

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#">

这篇关于如何获得标签“&lt; yweather:condition&gt;".从Yahoo Weather RSS in PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 00:38