ID: 47747 User updated by: mpeters at mac dot com Reported By: mpeters at mac dot com Status: Bogus Bug Type: DOM XML related Operating System: CentOS 5.2 PHP Version: 5.2.9 New Comment:
I updated the test case to create the attribute with the NS version of the function and the behavior is the same (as it also is if you load a valid xml file into DOMDocument) Here is why this needs to be fixed - script going through hundreds of elements, looking at the attributes. One element has 3 attributes that are the same but in different namespace. There's no way to generate an attribute list from which DOMAttr can distinguish the attributes as being in different namespaces, as it ignores the namespace with DOMAttr->name You may be able to distinguish via getAttributeNS but to use getAttributeNS you have to already know the namespace of the attribute you are looking at, and there seems to be no way to determine that from an attribute list (at least not generated by $node->attributes) So either because DOMAttr lacks functionality (ability to identify namespace) or because DOMAttr->name does the wrong thing (IE maybe it should include the namespace), the result is name clash that namespaces are suppose to avoid, thus DOM in php 5 is broken. Previous Comments: ------------------------------------------------------------------------ [2009-03-22 20:28:45] mpeters at mac dot com Not bogus - There is no way via DOMAttr to even know that an attribute name is part of a nanespace because DOMAttr->name DROPS the namespace and DOMAttr does not provide a facility by which to even know it was ever there. ------------------------------------------------------------------------ [2009-03-22 20:20:10] [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 Forgot to set it Bogus :) ------------------------------------------------------------------------ [2009-03-22 20:15:23] [email protected] you have to use the NS aware functions like setAttributeNS to get the correct behaivour, eg: $tag- >setAttributeNS("http://www.w3.org/XML/1998/namespace","xml:lang","en"); ------------------------------------------------------------------------ [2009-03-22 12:54:22] mpeters at mac dot com Full php demonstration - The code that demonstrates: http://www.clfsrpm.net/bugs/domattr.phps Execution of code: http://www.clfsrpm.net/bugs/domattr.php ------------------------------------------------------------------------ [2009-03-22 11:24:30] mpeters at mac dot com Description: ------------ I'm using php 5.2.5 - upgrading is not possible. Sorry. DOMattr->name does not include anything before a : nor provide a way to access what was before a : in an attribute name. Reproduce code: --------------- Let's say $node refers to the following node - <something xml:lang="en" foo="alpha" bar="beta" /> $attributes = $node->attributes; foreach ($attributes as attribute) { print ($attribute->name . "\n"); } will result in lang foo bar notice the xml: is missing from before the lang. DOMAttr provides no way to know that lang had a xml: before it. However - $node->hasAttribute('lang') is false while $node->hasAttribute('xml:lang') is true Expected result: ---------------- Either $DOMAttr->name needs to provide the full attribute name including namespace or provide a way to know what (if any) the namespace for the attribute name is. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=47747&edit=1
