|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34276 setAttributeNS doesn't work with non-prefixed attributes from default namespace
Submitted: 2005-08-27 02:26 UTC Modified: 2005-08-28 18:27 UTC
From: molily at gmx dot de Assigned:
Status: Closed Package: DOM XML related
PHP Version: 5CVS-2005-08-27 (snap) OS: Gentoo Linux
Private report: No CVE-ID: None
 [2005-08-27 02:26 UTC] molily at gmx dot de
It's not possible to use hasAttributeNS and getAttributeNS on attributes from the default namespace (i.e. without namespace prefix). They do not find the right attribute.

In addition to this, setAttributeNS cannot set an attribute in the default namespace. The new atttribute gets an incorrect namespace prefix.

I'm using the latest source snapshot php5-200508262230 (standard configuration but --without-pear) with libxml 2.6.20 (-r2 in Gentoo Portage).

Is this a libxml problem, like many DOM extension bugs before? Or do I misunderstand DOM 2 Core / XML Namespaces?

Reproduce code:
$dom = DOMDocument::loadXML('<a xmlns="" xmlns:y="" attra="attra" y:attrb="attrb" />');
$b = $dom->documentElement;
var_dump($b->hasAttributeNS('', 'attra'));
var_dump($b->hasAttributeNS('', 'attrb'));
var_dump($b->getAttributeNS('', 'attra'));
var_dump($b->getAttributeNS('', 'attrb'));
$b->setAttributeNS('', 'attra', 'attra neu');
$b->setAttributeNS('', 'attrb', 'attrb neu');
$b->setAttributeNS('', 'attrc', 'attrc');
$b->setAttributeNS('', 'attrd', 'attrd');
var_dump($b->getAttributeNS('', 'attra'));
var_dump($b->getAttributeNS('', 'attrb'));
var_dump($b->getAttributeNS('', 'attrc'));
var_dump($b->getAttributeNS('', 'attrd'));

Expected result:
(As far as I know:)

string(5) "attra"
string(5) "attrb"

string(9) "attra neu"
string(9) "attrb neu"
string(5) "attrc"
string(5) "attrd"

<?xml version="1.0"?>
<a xmlns="" xmlns:y="" attra="attra neu" y:attrb="attrb neu" attrc="attrc" y:attrd="attrd"/>

Actual result:
string(0) ""
string(5) "attrb"

string(0) ""
string(9) "attrb neu"
string(0) ""
string(5) "attrd"

<?xml version="1.0"?>
<a xmlns="" xmlns:y="" attra="attra" y:attrb="attrb neu" y:attra="attra neu" y:attrc="attrc" y:attrd="attrd"/>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-27 03:32 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

you misunderstood DOM 2 Core / XML Namespaces. Attributes dont  inherit from default namespace.
 [2005-08-27 21:46 UTC] molily at gmx dot de

 [2005-08-28 18:27 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

Yup, missed that part of the initial report
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC