php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47847 importNode loses the namespace of an XML element.
Submitted: 2009-03-31 11:20 UTC Modified: 2024-03-09 16:06 UTC
Votes:13
Avg. Score:4.4 ± 0.7
Reproduced:12 of 12 (100.0%)
Same Version:6 (50.0%)
Same OS:6 (50.0%)
From: robin2008 at altruists dot org Assigned: nielsdos (profile)
Status: Closed Package: DOM XML related
PHP Version: 5.2.9 OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: robin2008 at altruists dot org
New email:
PHP Version: OS:

 

 [2009-03-31 11:20 UTC] robin2008 at altruists dot org
Description:
------------
ImportNode don't treat namespace properly

Reproduce code:
---------------
<?php
// PHP 5.2.* namespace bug - A namespaced node loses its namespace on import if 
//		(i)  It has @xmlns=""
//		(ii) A namespaceURI of its parent's @xmlns

$aDOM= new DOMDocument();
$aDOM->appendChild($aDOM->createElementNS(' http://friend2friend.net ','f2f:a'));
echo 'DOM to add into is '.$aDOM->saveXML().chr(13);

$fromdom= DOMDocument::loadXML('<?xml version="1.0"?><f2f:data xmlns:f2f=" http://friend2friend.net "><f2f:servicereq xmlns=" http://friend2friend.net ">
<f2f:WATCH-MY-NAMESPACE xmlns=""/></f2f:servicereq></f2f:data>
');
echo 'Dom to import from is'.$fromdom->saveXML().chr(13);

$imported= $aDOM->importNode($fromdom->firstChild->firstChild, 1);
$aDOM->appendChild($imported);
echo 'Result is '.$aDOM->saveXML();
?>

Expected result:
----------------
Namespace should be preserved

Actual result:
--------------
Namespace gets lost

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2023-04-22 05:02 UTC] hunthealth8 at gmail dot com
Healthhunt are sharing latest news about Disease Management, Lifestyle & Wellness, Men's  Mental Health etc. More info to visit:(https://healthhunt.net)github.com
 [2023-06-16 21:18 UTC] nielsdos@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nielsdos
 [2023-06-16 21:18 UTC] nielsdos@php.net
The fix for this bug has been committed.
If you are still experiencing this bug, try to check out latest source from https://github.com/php/php-src and re-test.
Thank you for the report, and for helping us make PHP better.

Fixed via https://github.com/php/php-src/commit/b30be40b86b62fc681c432fd96840d8e57e172a5
 [2023-09-28 17:34 UTC] nielsdos@php.net
-Status: Closed +Status: Re-Opened
 [2023-09-28 17:34 UTC] nielsdos@php.net
Had to revert the fix unfortunately because some applications are dependent on a particular serialization. See https://github.com/php/php-src/pull/12308
I'm planning to work on spec-compliance related issues in the near future (in an opt-in manner), so I will consider this issue as a part of that effort.
 [2024-03-09 16:06 UTC] nielsdos@php.net
-Status: Re-Opened +Status: Closed
 [2024-03-09 16:06 UTC] nielsdos@php.net
The fix for this bug has been committed.
If you are still experiencing this bug, try to check out latest source from https://github.com/php/php-src and re-test.
Thank you for the report, and for helping us make PHP better.

This is fixed in the new opt-in spec-compliance mode, which was merged in https://github.com/php/php-src/pull/13031.
For more information about the opt-in mode, please see https://wiki.php.net/rfc/opt_in_dom_spec_compliance.
In short: the behaviour of the old DOM classes are unaffected for backwards-compatibility reasons. There are new DOM classes where your code is correctly handled.
This feature will be available in PHP 8.4.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC