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
  • possible duplicate of PHP namespace simplexml problems Commented Mar 1, 2011 at 14:29
  • Exact duplicate when using DOM: stackoverflow.com/questions/3268976/… Commented Mar 1, 2011 at 14:45
  • your "is not working" code is not working because you are doing it wrong: <yweather:condition> is a child of rss/channel/item while you are trying rss/condition Commented Mar 1, 2011 at 15:20

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.

Sign up to request clarification or add additional context in comments.

1 Comment

SimpleXMLElement Object ( ) . Also question edited please look again
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.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.