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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Mar 12 04:01:30 2025 UTC