Jump to content

PHP and XML


c_pattle

Recommended Posts

I have an XML document with this tag in it and I wanted to get the attribute values such as "fair", "33" and "18"

 

<yweather:condition text="Fair" code="33" temp="18" date="Thu, 01 Jul 2010 11:50 pm BST"/>

 

I have this code, however I get this error "

Fatal error: Call to a member function getAttribute() on a non-object in /var/www/nmic/index.php".  Can anyone help?

 

$xdoc = new DomDocument;
$xdoc->Load('http://weather.yahooapis.com/forecastrss?p=UKXX1270&u=c');
$candidatename = $xdoc->getElementsByTagName('yweather:condition')->item(0);
$attribNode = $candidatename->getAttribute('text');
echo "Attribute Name is :".$attribNode->name;
echo "<BR>Attribute Value is :".$attribNode->value;

Link to comment
https://forums.phpfreaks.com/topic/206500-php-and-xml/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.