I don't really understand how the current xml namespace handling in
simplexml is useful.

test.xml:

<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss";>
 <node>
  <title>Title1</title>
  <title>Title2</title>
  <media:title>Media Title</media:title>
 </node>
</rss>

$xml = simplexml_load_file('test.xml');
$xml->node ends up containing a title array that looks like this:

  ["title"]=>
  array(3) {
    [0] => string(6) "Title1"
    [1] => string(6) "Title2"
    [2] => string(11) "Media Title"
  }

Of course, I can loop through
$node->children('http://search.yahoo.com/mrss')
and get
  ["title "]=>
  object(SimpleXMLElement)#8 (1) {
    [0] => string(11) "Media Title"
  }

But how does this really help?  I don't see how it is possible to
distinguish the namespaced title vs. the non-namespaced ones.  My
suggestion here would be that for namespaced nodes the namespace alias
(or perhaps the actual namespace?) becomes the key in the nodes array.
As in:

  ["title"]=>
  array(3) {
    [0] => string(6) "Title1"
    [1] => string(6) "Title2"
    ['media'] => string(11) "Media Title"
  }

So people have a shot at distinguishing <media:title> from <title>

Or, alternatively, have a separate arrays:

  ["title"]=>
  array(2) {
    [0] => string(6) "Title1"
    [1] => string(6) "Title2"
  }
  ["media:title"]=>string(11) "Media Title"

The latter is actually what I was (naiively) expecting.

-Rasmus

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to