php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72454 Allow to specify indentation width when DOMDocument::formatOutput = true
Submitted: 2016-06-20 07:01 UTC Modified: 2019-09-23 19:09 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jonasschuermann at aol dot de Assigned: beberlei (profile)
Status: Wont fix Package: DOM XML related
PHP Version: 7.0.7 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jonasschuermann at aol dot de
New email:
PHP Version: OS:

 

 [2016-06-20 07:01 UTC] jonasschuermann at aol dot de
Description:
------------
I am using DOMDocument to pretty-print XML files:

$domDocument = new DomDocument();
$domDocument->preserveWhiteSpace = false;
$domDocument->formatOutput = true;
$domDocument->loadXML($uglyXml);
$prettyXml = $domDocument->saveXML();

The identiation width is hardcoded with 2 spaces. I would like to be able to specify a custom identiation width, something like

$domDocument->indentWidth = 4;

Test script:
---------------
$domDocument = new DomDocument();
$domDocument->preserveWhiteSpace = false;
$domDocument->formatOutput = true;
$domDocument->indentWidth = 4;
$domDocument->loadXML($uglyXml);
$prettyXml = $domDocument->saveXML();


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-24 00:00 UTC] cmb@php.net
-Summary: Allow to specify indentiation width when DOMDocument::formatOutput = true +Summary: Allow to specify indentation width when DOMDocument::formatOutput = true
 [2019-09-22 22:44 UTC] beberlei@php.net
This is technically possible if we add another option "formatOutputIndentSize" that proxies to the libxml indent_size option.
 [2019-09-23 19:09 UTC] beberlei@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: beberlei
 [2019-09-23 19:09 UTC] beberlei@php.net
This is actually not exposed in a nice way to modify in libxml, the underlying library that does the xml rendering in ext/dom. closing the ticket. sorry :(
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Oct 23 15:01:31 2019 UTC