Reputation: 7128
I'm using SimpleXML . I want to get this node's text attribute.
<yweather:condition text="Mostly Cloudy" ......
I'm using this it's not working :
$xml->children("yweather", TRUE)->condition->attributes()->text;
Upvotes: 0
Views: 491
Reputation: 3918
It looks like you are trying to access an attribute, which is stored in an array in $xml->yweather->attributes() so:
$attributes = $xml->condition->attributes();
$weather = $attributes['text'];
To deal with the namespace, you need to use children() to get the members of that namespace.
$weather_items = $xml->channel->item->children("http://xml.weather.yahoo.com/ns/rss/1.0");
It might help to mention that the string you showed is part of a feed, specifically the RSS formatted Yahoo Weather feed.
Upvotes: 0
Reputation: 6408
Do a print_r() on $xml to see how the structure looks. From there you should be able to see how to access the information.
Upvotes: 1
Reputation: 182
You would probably use $xml->condition but there may be branches before that.
Upvotes: 0