tags:

views:

34

answers:

1

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&outputtype=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?

+2  A: 

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

See getElementsByTagNameNS

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

Jamie Wong
So would I do something like getElementsByTagNameNS('http://www.aws.com/aws', 'weather');?Because that doesn't work
CMC