PHPackages                             simonschaufi/pretty-xml - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. simonschaufi/pretty-xml

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

simonschaufi/pretty-xml
=======================

Library for pretty-printing XML

3.0.0(1y ago)22164.8k↑17.6%91MITPHPPHP ^7.4 || ^8.0CI passing

Since Jul 18Pushed 1y ago3 watchersCompare

[ Source](https://github.com/simonschaufi/pretty-xml)[ Packagist](https://packagist.org/packages/simonschaufi/pretty-xml)[ Fund](https://www.paypal.me/simonschaufi/10)[ GitHub Sponsors](https://github.com/simonschaufi)[ RSS](/packages/simonschaufi-pretty-xml/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)DependenciesVersions (9)Used By (1)

pretty-xml
==========

[](#pretty-xml)

A tiny library for pretty printing XML, inspired purely from DomDocument's lack of ability to configure indent distance.

[![Latest Stable Version](https://camo.githubusercontent.com/9b5f37f3578e536d05713ee3826c57540a264193fe825f3a0cf71800e5215e4a/68747470733a2f2f706f7365722e707567782e6f72672f73696d6f6e736368617566692f7072657474792d786d6c2f762f737461626c65)](https://packagist.org/packages/simonschaufi/pretty-xml)[![Total Downloads](https://camo.githubusercontent.com/5dbdd2db680b1bb84428e795e2e923cdd140cf26266b9a59a1c0fe3fe9a3a8f0/68747470733a2f2f706f7365722e707567782e6f72672f73696d6f6e736368617566692f7072657474792d786d6c2f646f776e6c6f616473)](https://packagist.org/packages/simonschaufi/pretty-xml)

Usage
-----

[](#usage)

### Installation

[](#installation)

The recommended way to install the extension is using [Composer](https://getcomposer.org/).

Run the following command:

```
composer require simonschaufi/pretty-xml
```

### How to use

[](#how-to-use)

#### Prettify

[](#prettify)

To use, give it a badly indented (but well-formed and valid) XML string:

```
use PrettyXml\Formatter;

$formatter = new Formatter();
echo "" . htmlspecialchars($formatter->format('Baz')) . "";
```

You can also change the size of the indent:

```
$formatter->setIndentSize(2);
```

And you can change the indent character:

```
$formatter->setIndentCharacter("\t");
```

#### Minify

[](#minify)

```
use PrettyXml\Formatter;

$formatter = new Formatter();
echo htmlspecialchars($formatter->minify(
