开发者

PHP XML DOM - getElementsByTagName

I'm trying to use the weatherbug API, but seem to be stuck quite early in the proceedings.

The [very simple] code I tried:

function weather_widget($apikey, $zipcode) {
  $url = "http://$apikey.api.wxbug.net/getLiveWeatherRSS.aspx?ACode=$apikey&zipcode=$zipcode&unittype=0&o开发者_StackOverflow中文版utputtype=1";
  $contents = file_get_contents($url);
  $doc = new DOMDocument();
  $doc->loadXML($contents);
  return $doc->getElementsByTagName('aws:weather');
}

var_dump(weather_widget($key, $code));

This produced:

object(DOMNodeList)#2 (0) { }

Does XML DOM not work with at tagname that contains :'s?


The aws isn't part of the tagname - it's the namespace.

See getElementsByTagNameNS

http://www.php.net/manual/en/domdocument.getelementsbytagnamens.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜