Build Status Actions Status Actions Status Actions Status

NAME

XML::Minifier - A configurable XML minifier.

WARNING

The API (option names) is almost stabilized (but not fully) and can therefore still change a bit.

SYNOPSIS

Here is the simplest way to use XML::Minifier :

use XML::Minifier;

my $maxi = "<person>   <name>tib   </name>   <level>  42  </level>  <city>   </city>  </person>";
my $mini = minify($maxi);

But a typical use would include some parameters like this :

use XML::Minifier qw(minify);

my $maxi = "<person>   <name>tib   </name>   <level>  42  </level>  <city>   </city>  </person>";
my $mini = minify($maxi, no_prolog => 1, aggressive => 1);

That will produce :

<person><name>tib</name><level>42</level><city/></person>

aggressive, destructive and insane are shortcuts that define a set of parameters.

You can set indivually with :

use XML::Minifier qw(minify);

my $maxi = "<person>   <name>tib   </name>   <level>  42  </level>  <city>   </city>  </person>";
my $mini = minify($maxi, no_prolog => 1, aggressive => 1, keep_comments => 1, remove_indent => 1);

The code above means "minify this string with aggressive mode BUT keep comments and in addition remove indent".

Not every parameter has a keep_ neither a remove_, please see below for detailed list.

DEFAULT MINIFICATION

The minifier has a predefined set of options enabled by default.

They were decided by the author as relevant but you can disable individually with keep_ options.

In addition, the minifier will drop every blanks between the first level children. What you can find between first level children is not supposed to be meaningful data then we we can safely remove formatting here. For instance we can remove a carriage return between prolog and a processing instruction (or even inside a DTD).

In addition again, the minifier will smartly remove blanks between tags. By smart I mean that it will not remove blanks if we are in a leaf (more chances to be meaningful blanks) or if the node contains something that will persist (a not removed comment/cdata/PI, or a piece of text not empty). The meaningfulness of blanks can be given by a DTD. Then if a DTD is present and *protects some nodes*, we oviously respect this. But you can decide to change this behaviour with **ignore_dtd** option.

If there is no DTD (very often), we are blind and simply use the approach I just described above (keep blanks in leafs, remove blanks in nodes if all siblings contains only blanks).

Everything listed above is the default and should be perceived as almost lossyless minification in term of semantic (for humans).

It's not completely if you consider these things as data, but in this case you simply can't minify as you can't touch anything ;)

EXTRA MINIFICATION

In addition, you could enable mode aggressive, destructive or insane to remove characters in the text nodes (sort of "cleaning") :

Aggressive

Destructive

Insane

OPTIONS

You can give various options:

LICENSE

Copyright (C) Thibault DUPONCHELLE.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Thibault DUPONCHELLE