php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30966 set_attribute with namespace breaks xml
Submitted: 2004-12-02 21:02 UTC Modified: 2004-12-02 23:25 UTC
From: theseer@php.net Assigned:
Status: Wont fix Package: DOM XML related
PHP Version: 4.3.9 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
29 + 19 = ?
Subscribe to this entry?

 
 [2004-12-02 21:02 UTC] theseer@php.net
Description:
------------
When using $node->set_attribute on a previously existing attribute with a namespace, the attribute gets doubled rather then updated - interestingly enough, a second update does update the "doubled" attribute just fine...

Additionally, $node->remove_attribute('test:attrib'); doesn't work with the previously existing attribute either while it removes the newly doubled attribute.

Reproduce code:
---------------
$dom=domxml_open_mem('<?xml version="1.0" ?><foo:root xmlns:test="http://test.de/xml" xmlns:foo="http://test.de/foo" test:attrib="0" />');

 $root = $dom->document_element();  
 $root->set_attribute('test:attrib','1');
 $root->set_attribute('test:attrib','2');
 
 echo $dom->dump_mem();

Expected result:
----------------
<?xml version="1.0"?>
<foo:root xmlns:test="http://test.de/xml" xmlns:foo="http://test.de/foo" test:attrib="2"/>

Actual result:
--------------
<?xml version="1.0"?>
<foo:root xmlns:test="http://test.de/xml" xmlns:foo="http://test.de/foo" test:attrib="0" test:attrib="2"/>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-02 21:03 UTC] theseer@php.net
LibXML2 Version is 2.6.16
 [2004-12-02 21:07 UTC] theseer@php.net
Just found a "workaround" to avoid invalid xml:

  $root->remove_attribute('attrib');  

That will remove the "original" attribute. Yes, without the namespace-prefix!
 [2004-12-02 23:25 UTC] chregu@php.net
Namespace Support is pretty week in PHP 4...

If your solution works for you, fine. But it's not the DOM way to do it. It would be ->set_attribute_ns($namespaceURL,$attributeName)
But that doesn't exits in domxml in php4

That's all fixed in php5 and dom.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 06:01:30 2024 UTC