|  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
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.
Block user comment
Status: Assign to:
Bug Type:
From: jonasschuermann at aol dot de
New email:
PHP Version: OS:


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

$domDocument = new DomDocument();
$domDocument->preserveWhiteSpace = false;
$domDocument->formatOutput = true;
$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;
$prettyXml = $domDocument->saveXML();


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-24 00:00 UTC]
-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]
This is technically possible if we add another option "formatOutputIndentSize" that proxies to the libxml indent_size option.
 [2019-09-23 19:09 UTC]
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: beberlei
 [2019-09-23 19:09 UTC]
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-2024 The PHP Group
All rights reserved.
Last updated: Wed May 22 07:01:34 2024 UTC