The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

xml-minifier - Minify XML files

SYNOPSIS

xml-minifier file.xml

OR

cat file.xml | xml-minifier

Options:

--expand-entities expand entities

--process-xincludes process xincludes

--remove-blanks-start remove blanks before text

--remove-blanks-end remove blanks after text

--remove-spaces-line-start remove spaces/tabs before text (each line)

--remove-spaces-line-end remove spaces/tabs after text (each line)

--remove-indent remove spaces/tabs before text (each line

--remove-empty-text remove (pseudo) empty text

--remove-cr-lf-everywhere remove cr and lf everywhere

--keep-comments keep comments

--keep-cdata keep cdata

--keep-pi keep processing instructions

--keep-dtd keep dtd

--ignore-dtd ignore dtd

--no-prolog remove prolog (version and encoding)

--version specify version for the xml

--encoding specify encoding for the xml

--aggressive enable aggressive mode

--destructive enable aggressive mode

--insane enable aggressive mode

--help brief help message

OPTIONS

--expand-entities

Expand entities. An entity is like &foo;

--process-xincludes

Process xicnludes. An xinclude is like <xi:include href="inc.xml"/>

--remove-blanks-start

Remove blanks (spaces, carriage return, line feed...) in front of text nodes. For instance <tag> foo bar</tag> will become <tag>foo bar</tag> Agressive and therefore lossy compression.

--remove-blanks-end

Remove blanks (spaces, carriage return, line feed...) at the end of text nodes. For instance <tag>foo bar </tag> will become <tag>foo bar</tag> Agressive and therefore lossy compression.

--remove-spaces-line-start

Remove spaces and tabs at the start of each line of text nodes. Agressive and therefore lossy compression.

--remove-spaces-line-end

Remove spaces and tabs at the end of each line of text nodes. Agressive and therefore lossy compression.

--remove-indent

Remove spaces and tabs at the start of each line of text nodes. It is actually an alias of --remove-spaces-line-start Agressive and therefore lossy compression.

--remove-empty-text

Remove (pseudo) empty text nodes (spaces, carriage return, line feed...).

--remove-cr-lf-everywhere

Remove carriage returns and line feed everywhere (inside text !). For instance <tag>foo\nbar</tag> will become <tag>foobar</tag> Very aggressive and therefore lossy compression.

--keep-comments

Keep comments, by default they are removed. A comment is like <!-- comment -->

--keep-cdata

Keep cdata, by default they are removed. A CDATA is like <![CDATA[ my cdata ]]>

--keep-pi

Keep processing instructions. A processing instruction is like <?xml-stylesheet href="style.css"/>

--keep-dtd

Keep DTD.

--ignore-dtd

Do not read DTD. The minifier reads the DTD to get informations about meaningful blanks.

--no-version

Do not put any version.

--version

Specify version.

--encoding

Specify encoding.

--aggressive

Enable aggressive mode. Enables options --remove-blanks-starts --remove-blanks-end --remove-empty-text if they are not defined only. Other options still keep their value.

--destructive

Enable destructive mode. Enable options --remove-spaces-line-starts --remove-spaces-line-end if they are not defined only. Enable also aggressive mode. Other options still keep their value.

--insane

Enable insane mode. Enables options --remove-cr-lf-everywhere --remove-spaces-everywhere if they are not defined only. Enable also destructive mode and insane mode. Other options still keep their value.

--help

Print a brief help message and exits.

DESCRIPTION

This program will read the standard input and minify

Remove all useless formatting between nodes.
Remove dtd.
Remove processing instructions
Remove comments.
Remove CDATA.

This is the default and should be perceived as lossyless minification in term of semantic (but it's not completely if you consider these things as data). If you want a full lossyless minification, just use --keep arguments.

In addition, you could be morte brutal and remove characters in the text nodes (sort of "cleaning") :

Remove empty text nodes.
Remove starting blanks (carriage return, line feed, spaces...).
Remove ending blanks (carriage return, line feed, spaces...).
Remove carriage returns and line feed into text node everywhere.
Remove spaces text node everywhere.
Remove indentation in text node.
Remove invisible spaces in text node.