Bug->Doc #74491 [Opn->Ver]: XMLWriter adds to many namespace definitions
| From: | cmb@php.net | Date: | Mon, 02 Apr 2018 22:51:58 +0000 |
| Subject: | Bug->Doc #74491 [Opn->Ver]: XMLWriter adds to many namespace definitions | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-15583@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
Updated by: cmb@php.net
Reported by: subjective@php.net
Summary: XMLWriter adds to many namespace definitions
-Status: Open
+Status: Verified
-Type: Bug
+Type: Documentation Problem
Package: XML Writer
PHP Version: 7.1.4
Block user comment: N
Private report: N
New Comment:
> [â¦] altho I suspect the problem is actually with xmlwrite.c in
> libxml, hence it's probably not be up to PHP to fix it [â¦]
That!
> [â¦] simply pass null as the namespaceURI argument to
> XMLWriter::writeElementNS() and kin.
Dead-on, again! Thanks! Hence, I'm changing to documentation
issue. (By the way, the $prefix can also be NULL, to omit the
namespace).
Previous Comments:
------------------------------------------------------------------------
[2017-06-28 18:09:49] 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.
------------------------------------------------------------------------
[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