php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #74492 XMLWriter adds indent between mixed child nodes.
Submitted: 2017-04-23 10:58 UTC Modified: 2020-10-27 13:27 UTC
From: subjective@php.net Assigned: cmb (profile)
Status: Closed Package: XML Writer
PHP Version: 7.1.4 OS:
Private report: No CVE-ID: None
 [2017-04-23 10:58 UTC] subjective@php.net
Description:
------------
XMLWriter adds the defined indent between mixed child nodes. This will change the meaning if the text nodes do not contain leading/trailing whitespaces.

This does not happen if the indent is set to zero.



Test script:
---------------
<?php
$_ = new XMLWriter();
$_->openMemory();
$_->setIndent(2);

$_->startDocument();
$_->startElement('p');
$_->text('before');
$_->writeElement('a', 'element');
$_->text('after');
$_->endElement();
$_->endDocument();

echo $_->outputMemory();

Expected result:
----------------
<?xml version="1.0"?>
<p>before<a>element</a>after</p>

Actual result:
--------------
<?xml version="1.0"?>
<p>before <a>element</a>
after</p>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-04-02 22:05 UTC] cmb@php.net
-Status: Open +Status: Analyzed
 [2018-04-02 22:05 UTC] cmb@php.net
ext/xmlwriter is a rather thin layer over libxml2's xmlwriter
module[1], and this is the way that xmlTextWriterSetIndent() works
(currently). It might be worthwhile to report this issue
upstream[2], but pretty printing might better be left to
specialized tools, anyway.

In my opinion, it is best to make this a documentation issue, and
to convey that ::setIndent() is not necessarily suitable for mixed
content.

By the way, XMLWriter::setIndent() expects a boolean argument, not
an integer.

[1] <http://xmlsoft.org/html/libxml-xmlwriter.html>
[2] <https://bugzilla.gnome.org/buglist.cgi?product=libxml2>
 [2018-04-02 22:05 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem
 [2020-10-27 13:27 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2020-10-27 13:30 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=48f89dadf5671109df0164637f40fab4bbf8148c
Log: Fix #74492: XMLWriter adds indent between mixed child nodes
 [2020-10-27 13:30 UTC] phpdocbot@php.net
-Status: Analyzed +Status: Closed
 [2020-10-27 19:25 UTC] phpdocbot@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=95e43b7293b8e1bccb96f7bf62b36af991cf6def
Log: Fix #74492: XMLWriter adds indent between mixed child nodes / Remove erroneous notes
 [2020-12-30 11:58 UTC] nikic@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=aa990367f1cc386594195e49b01802023ee52274
Log: Fix #74492: XMLWriter adds indent between mixed child nodes / Remove erroneous notes
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 19:01:29 2024 UTC