Bug #74491 [Com]: XMLWriter adds to many namespace definitions
| From: | paul at sparrowhawkcomputing dot com | Date: | Wed, 28 Jun 2017 18:09:53 +0000 |
| Subject: | Bug #74491 [Com]: XMLWriter adds to many namespace definitions | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-209715@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74491&edit=1
ID: 74491
Comment by: paul at sparrowhawkcomputing dot com
Reported by: subjective@php.net
Summary: XMLWriter adds to many namespace definitions
Status: Open
Type: Bug
Package: XML Writer
PHP Version: 7.1.4
Block user comment: N
Private report: N
New Comment:
I very much agree that this should be fixed; altho I suspect the problem is actually with xmlwrite.c
in libxml, hence it's probably not be up to PHP to fix it :-( But maybe the PHP powers that be
can put some pressure on libxml to fix it.
Until it does get fixed, there is a fairly simple workaround:
If you know there is an in-scope namespace decl aready written (i.e., on an ancestor element) then
simply pass null as the namespaceURI argument to XMLWriter::writeElementNS() and kin.
Previous Comments:
------------------------------------------------------------------------
[2017-04-23 10:44:25] subjective@php.net
Description:
------------
XMLWriter adds namespace definitions to any element node that is created by by a namespace aware
method. It does not take definitions on parent nodes into account. The resulting XML output is valid
and has even the same meaning, but it is a lot larger then needed.
Test script:
---------------
<?php
$_ = new XMLWriter();
$_->openMemory();
$_->setIndent(2);
$_->startDocument();
$_->startElementNS('a', 'foo', 'urn:a');
$_->writeElementNS('a', 'bar', 'urn:a', 'foobar');
$_->endElement();
$_->endDocument();
echo $_->outputMemory();
Expected result:
----------------
<?xml version="1.0"?>
<a:foo xmlns:a="urn:a">
<a:bar>foobar</a:bar>
</a:foo>
Actual result:
--------------
<?xml version="1.0"?>
<a:foo xmlns:a="urn:a">
<a:bar xmlns:a="urn:a">foobar</a:bar>
</a:foo>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74491&edit=1