0

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;
3

3 Answers 3

1

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.

1
  • SimpleXMLElement Object ( ) . Also question edited please look again
    – Eray
    Commented Mar 1, 2011 at 14:44
0

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.

0

You would probably use $xml->condition but there may be branches before that.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.