php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47747 DOMAttr returns incomplete attribute name
Submitted: 2009-03-22 11:24 UTC Modified: 2009-03-24 08:40 UTC
From: mpeters at mac dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.9 OS: CentOS 5.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mpeters at mac dot com
New email:
PHP Version: OS:

 

 [2009-03-22 11:24 UTC] 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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-22 12:54 UTC] 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 20:15 UTC] chregu@php.net
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 20:20 UTC] chregu@php.net
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:28 UTC] 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:57 UTC] mpeters at mac dot com
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.
 [2009-03-22 21:08 UTC] mpeters at mac dot com
Nevermind - I got it figured out.
It is bogus
 [2009-03-23 19:13 UTC] chregu@php.net
Just for the record, if anyone is looking at that bug later:

the following properties do also exist (but are not in the documentation 
yet)

$attribute->namespaceURI
$attribute->prefix
$attribute->localName
$attribute->nodeName; 

 [2009-03-24 08:40 UTC] mpeters at mac dot com
cool!
Those properties just greatly reduced the code for what I am trying to accomplish. Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 18:01:30 2024 UTC