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
Share on other sites

The XML feed you are getting from yahoo is actually a RSS feed. It would be much easier if you download an rss reader class from phpclasses.org and let the parser get the correct information for you instead of parsing it manually.

 

I hope this helps

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.