Re: Simplexml and xml namespaces
| From: | Rasmus Lerdorf | Date: | Fri, 19 Aug 2005 06:59:06 +0000 |
| Subject: | Re: Simplexml and xml namespaces | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-18220@lists.php.net to get a copy of this message | ||
Sterling Hughes wrote:
> Hm - that shouldn't be.
>
> I think the right solution is that media:title should not show up in
> the children of node, unless you are looking at the proper namespace,
> ie, you need to use children() to get the children in that namespace.
Ah, you are right. It's the damn var_dump() problem again.
eg.
$xml = <<<EOF
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss">
<node>
<title>Title</title>
<media:title>Media Title</media:title>
</node>
</rss>
EOF;
$x = simplexml_load_string($xml);
var_dump($x->node) shows:
object(SimpleXMLElement)#2 (1) {
["title"]=>
array(2) {
[0]=>
string(6) "Title"
[1]=>
string(11) "Media Title"
}
}
but var_dump($x->node->title) shows:
object(SimpleXMLElement)#4 (1) {
[0]=>
string(6) "Title"
}
There should be a simplexml_dump() or something along those lines and
perhaps even a warning in var_dump() when it tries to dump an object
that has its own iterator.
-Rasmus