Bug #47531 [Com]: No way of removing redundant xmlns: declarations
| From: | decorationhouse79 at gmail dot com | Date: | Tue, 09 May 2023 07:33:25 +0000 |
| Subject: | Bug #47531 [Com]: No way of removing redundant xmlns: declarations | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-244406@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=47531&edit=1
ID: 47531
Comment by: decorationhouse79 at gmail dot com
Reported by: sgunderson at bigfoot dot com
Summary: No way of removing redundant xmlns: declarations
Status: Open
Type: Bug
Package: DOM XML related
Operating System: Debian
PHP Version: 5.3CVS-2009-02-28 (snap)
Block user comment: N
Private report: N
New Comment:
House Construction ews about home, cons cleaning, design, decoration etc. More info to
visit:(https://houseconstructioninfo.com)github.com
Previous Comments:
------------------------------------------------------------------------
[2013-06-02 16:30:44] 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
------------------------------------------------------------------------
[2009-06-14 19:06:43] 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.
------------------------------------------------------------------------
[2009-02-28 15:19:14] 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>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=47531&edit=1