XML_PP(1)
π xml_pp(1) β the pretty-printer page, bestie edition β¨
okay so this is xml_pp, aka the xml pretty-printer. that's the whole name section, we ate that π
π SYNOPSYS
xml_pp [options] [<files>]
π¦ DESCRIPTION
it's an XML pretty printer, and it runs on XML::Twig π. that's the vibe. it takes your crusty one-line XML and makes it look β¨iconicβ¨.
π OPTIONS
-i[<extension>]β edits the file(s) in place, no cap. and if you hand it an extension (with no space between-iand the extension, okay? like-i.bak, not-i .bak, we don't do that) then the original file gets backed up with that extension π«Ά
the rules for the extension are literally the same as Perl's (peep perldoc perlrun for the tea β): if the extension has no * in it, it just gets appended to the original file name. if the extension has one or more * characters, then each * gets replaced with the current filename. slay.
-s <style>β the style to use for pretty printing. your options are:none,nsgmls,nice,indented,record, orrecord_c(go read theXML::Twigdocs for the exact description of those styles, i'm not gonna pretend i can out-explain them). default is'indented'π-p <tag(s)>β preserves white spaces in tags. you can use several-poptions, or just quote the tags if you need more than one π-e <encoding>β usesXML::Twigoutput_encoding(which is based onText::IconvorUnicode::Map8andUnicode::String, iykyk) to set the output encoding. by default the original encoding is preserved, no notes.
if you use this option, the XML declaration gets updated β and created if there wasn't one already β¨
β οΈ make sure the encoding is supported by the parser you use, if you want to actually be able to process the pretty_printed file. like,XML::Parserdoes not support'latin1'for example β you gotta use'iso-8859-1'. don't ask me why, just trust me π
-lβ loads the documents in memory instead of outputting them as they're being parsed. this prevents a bug (see BUGS below) but uses more memory. tradeoff city π-f <file>β reads the list of files to process from <file>, one per line π-vβ verbose, aka it lists the current file being processed. main character energy for your terminal πΈ--β stop argument processing. use this to process files that start with-(yes, those exist, we've all been there) π-hβ display help π
β EXAMPLES
xml_pp foo.xml > foo_pp.xml # pretty print foo.xml
xml_pp < foo.xml > foo_pp.xml # pretty print from standard input
xml_pp -v -i.bak *.xml # pretty print .xml files, with backups
xml_pp -v -i'orig_*' *.xml # backups are named orig_<filename>
xml_pp -i -p pre foo.xhtml # preserve spaces in pre tags
xml_pp -i.bak -p 'pre code' foo.xml # preserve spaces in pre and code tags
xml_pp -i.bak -p pre -p code foo.xml # same
xml_pp -i -s record mydb_export.xml # pretty print using the record style
xml_pp -e utf8 -i foo.xml # output will be in utf8
xml_pp -e iso-8859-1 -i foo.xml # output will be in iso-8859-1
xml_pp -v -i.bak -f lof # pretty print in place files from lof
xml_pp -- -i.xml # pretty print the -i.xml file
xml_pp -l foo.xml # loads the entire file in memory
# before pretty printing it
xml_pp -h # display help
π BUGS
so there's this one bug bestie. elements with mixed content that start with an embedded element get an extra \n. like, this:
<elt><b>b</b>toto<b>bold</b></elt>
will be output as:
<elt>
<b>b</b>toto<b>bold</b></elt>
not me crying over a stray newline π. using the -l option solves this bug (but uses more memory, as established π«Ά)
π§ TODO
update XML::Twig to use Encode with perl 5.8.0 β it's on the list, it's giving "i'll get to it" β¨
π AUTHOR
Michel Rodriguez <mirod@xmltwig.com> π
and that's the whole page, babe π β brought to you by perl v5.42.0 and dated 2025-01-16, so you know exactly which era of slay this is from. mwah π
π
π¦ where this page comes from
- opensuse-leap 16.0: perl-XML-Twig 3.530.0-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms