ID:               42026
 User updated by:  mail_ben_schmidt at yahoo dot com dot au
 Reported By:      mail_ben_schmidt at yahoo dot com dot au
-Status:           Bogus
+Status:           Open
 Bug Type:         SimpleXML related
 Operating System: Mac OS X
 PHP Version:      5.2.3
 New Comment:

Telling me to check the manual is somewhat useless, as this module is
poorly documented, particularly in this area. The best 'documentation'
available from what I can gather is at

http://devzone.zend.com/node/view/id/688#Heading3

where it states, "If no namespace is passed to the children() function,
all the elements in the global namespace are returned."

This is clearly not the behaviour exhibited, because in the case in
question the 'global namespace' *is* the namespace 'ns' (in the first
six <elem>s anyway). Regardless of whether an element is in that
namespace by virtue of a prefix or by default, it is still in the global
namespace.

Purely from a logical perspective, though, the behaviour is clearly
wrong. To the XML author

<root xmlns="a" xmlns:ns="b">
<elem attr="something">
</root>

is equivalent to

<root xmlns="a" xmlns:ns="b">
<ns:elem attr="something">
</root>

which is equivalent to

<root xmlns="a" xmlns:ns="b">
<ns:elem ns:attr="something">
</root>

and so on, and any author should have the right to expect both those
snippets (and other such modifications) to be treated identically by any
parser/XML binding system, as they mean exactly the same thing. The
difference is merely one of stylistic choice or ease of implementation
of some XML generator, and it shouldn't have the side-effect/ability of
hiding things from some XML application/script.

I would be happy to have a go fixing the bug unless the consensus of
the developers truly is that this shouldn't be fixed. Or even perhaps if
it is, as it would simply my application. I can think of a couple of
workarounds, but they aren't very pleasant.


Previous Comments:
------------------------------------------------------------------------

[2007-07-18 11:59:17] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Works as it should. Not specifying a namespace returns un-prefixed
elements (no or default namespace), as no namespace testing is performed
other than checking for no prefix. There is no default namespace for
attributes.

------------------------------------------------------------------------

[2007-07-18 11:12:26] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.2-win32-installer-latest.msi

Some fixes were already done regarding namespaces.

------------------------------------------------------------------------

[2007-07-18 11:12:22] mail_ben_schmidt at yahoo dot com dot au

Irrelevant to the bug itself, but one of my numbers that were meant to
be helpful in the code example was wrong. Should have read:

<other:elem attr="abc"/>1
<other:elem ns:attr="abc"/>0
<other:elem other:attr="abc"/>1

------------------------------------------------------------------------

[2007-07-18 11:09:01] mail_ben_schmidt at yahoo dot com dot au

Description:
------------
When getting children/attributes without using methods to specify a
namespace explicity, non-prefixed names are returned, but not prefixed
ones, even if the prefixed names are in the same namespace.

(Note that in fixing this bug there is a subtlety: the default
namespace for attributes is inherited from the element in which they
appear.)



Reproduce code:
---------------
$str=<<<DONE
<?xml version="1.0" encoding="utf-8"?>
<root
        xmlns="http://localhost/a";
        xmlns:ns="http://localhost/a";
        xmlns:other="http://localhost/b";
>
<elem attr="abc"/>1
<elem ns:attr="abc"/>1
<elem other:attr="abc"/>0
<ns:elem attr="abc"/>1
<ns:elem ns:attr="abc"/>1
<ns:elem other:attr="abc"/>0
<other:elem attr="abc"/>0
<other:elem ns:attr="abc"/>0
<other:elem other:attr="abc"/>1
</root>
DONE;

$xml = simplexml_load_string($str);
foreach ($xml->elem as $elem) {
        echo count($elem->attributes());
}
echo "\n";
foreach ($xml->children('http://localhost/a')->elem as $elem) {
        echo count($elem->attributes());
}
echo "\n";
foreach ($xml->children('http://localhost/b')->elem as $elem) {
        echo count($elem->attributes());
}
echo "\n";


Expected result:
----------------
110110 110110 101

Actual result:
--------------
100 100100 100


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=42026&edit=1
  • #42026 [Bgs->Opn]: Incorrect h... mail_ben_schmidt at yahoo dot com dot au

Reply via email to