ID: 42026 Updated by: [EMAIL PROTECTED] Reported By: mail_ben_schmidt at yahoo dot com dot au -Status: Open +Status: Bogus Bug Type: SimpleXML related Operating System: Mac OS X -PHP Version: 5.2CVS-2007-07-18 +PHP Version: 5.2.3 New Comment:
The behavior is correct and that statement was not exactly correct concerning the behavior. The intended behavior is to operate on non-prefixed elements without checking namespace or operating on elements within a specific namespace when instructed. There is no bug here and those referenced documents are not exactly the same (an attribute without a prefix does not fall into default namespace like an element does). Previous Comments: ------------------------------------------------------------------------ [2007-07-18 13:52:49] mail_ben_schmidt at yahoo dot com dot au O, and yes, I did try the CVS version, and it behaves the same way. I didn't do 'make install' but just ran the binary in place, but I presume this wouldn't have an impact. If that isn't a valid test, let me know, and I will reconfigure with some temporary prefix and 'make install'. Forgot to mention in previous post. ------------------------------------------------------------------------ [2007-07-18 13:48:58] mail_ben_schmidt at yahoo dot com dot au 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. ------------------------------------------------------------------------ [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: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
