php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47531 No way of removing redundant xmlns: declarations
Submitted: 2009-02-28 15:19 UTC Modified: 2017-10-24 06:15 UTC
Votes:15
Avg. Score:3.9 ± 1.1
Reproduced:13 of 13 (100.0%)
Same Version:1 (7.7%)
Same OS:1 (7.7%)
From: sgunderson at bigfoot dot com Assigned:
Status: Closed Package: DOM XML related
PHP Version: 5.3CVS-2009-02-28 (snap) OS: Debian
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: sgunderson at bigfoot dot com
New email:
PHP Version: OS:

 

 [2009-02-28 15:19 UTC] sgunderson at bigfoot dot com
Description:
------------
There seems to be no good way of manipulating XML namespace declarations at all. In particular, they never get garbage collected in any way, and you cannot remove them manually, so they will stick around forever unless you create a new one. My typical use case is shown in the reproduce code below (although the element will typically have child elements).

Since 5.3 (bug #38949) it seems I can getAttribute() the xmlns element, but still not remove it it any reasonable way (and it should really just disappear by itself; it does in other languages).

Reproduce code:
---------------
<?php

$doc = new DOMDocument;
$doc->loadXML('<html xmlns="something"><element xmlns:ns="whatever" ns:foo="bar" /></html>');
$root = $doc->documentElement;
$elem = $root->firstChild;
$elem->removeAttributeNode($elem->attributes->item(0));
print $doc->saveXML();

?>


Expected result:
----------------
<?xml version="1.0"?>
<html xmlns="something"><element/></html>


Actual result:
--------------
<?xml version="1.0"?>
<html xmlns="something"><element xmlns:ns="whatever"/></html>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-14 19:06 UTC] robin2009 at altruists dot org
You can run DOMs through an XSLT identity transform to strip redundant namespaces, since this removes (what it deems to be) unused namespaces (i.e. namespaces which don't appear as elements or attributes).

This method is not only slow for large DOMs, if you're working with XSDs or XSLTs, both of which use namespaces inside attribute values, it would need modification, since XSLT strips them.
 [2010-06-20 21:31 UTC] felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: rrichards
 [2013-06-02 16:30 UTC] ekuratopen at spamavert dot com
> Since 5.3 (bug #38949) it seems I can getAttribute() the xmlns element, but still not remove it it any reasonable way

you may remove the namespace attribute by using
---
$e = $doc->documentElement;
$e->removeAttributeNS($e->getAttributeNode('xmlns')->nodeValue, '');
---
so you will not need to do registerNamespace() in DOMXPath if DOM has it for example
 [2017-10-24 06:15 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: rrichards +Assigned To:
 [2023-05-09 07:33 UTC] decorationhouse79 at gmail dot com
House Construction ews about home, cons cleaning, design, decoration etc. More info to visit:(https://houseconstructioninfo.com)github.com
 [2023-10-28 13:48 UTC] git@php.net
Automatic comment on behalf of nielsdos
Revision: https://github.com/php/php-src/commit/f9a24969d056088a21c91313ae4048820f35ef22
Log: Fix #47531: No way of removing redundant xmlns: declarations
 [2023-10-28 13:48 UTC] git@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC