|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74491 XMLWriter adds to many namespace definitions
Submitted: 2017-04-23 10:44 UTC Modified: -
Avg. Score:4.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: Assigned:
Status: Open Package: XML Writer
PHP Version: 7.1.4 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-04-23 10:44 UTC]
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:
$_ = new XMLWriter();

$_->startElementNS('a', 'foo', 'urn:a');
$_->writeElementNS('a', 'bar', 'urn:a', 'foobar');

echo $_->outputMemory();

Expected result:
<?xml version="1.0"?>
<a:foo xmlns:a="urn:a">

Actual result:
<?xml version="1.0"?>
<a:foo xmlns:a="urn:a">
  <a:bar xmlns:a="urn:a">foobar</a:bar>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-28 18:09 UTC] paul at sparrowhawkcomputing dot com
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.
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC