XML_PP(1p)
π xml_pp β the pretty-printer era π
okay bestie, so this is XML_PP(1p), from the User Contributed Perl Documentation section, and it's literally the glow-up your ugly XML has been begging for. no cap. π¦
β¨ NAME β¨
xml_pp β xml pretty-printer. that's it, that's the name, and it ate. π
β¨ SYNOPSYS β¨
xml_pp [options] [<files>]
(yes the section is spelled like that, i'm not fixing it, it's iconic π)
β¨ DESCRIPTION β¨
so basically? XML pretty printer using XML::Twig. it takes your crusty unreadable XML and makes it serve main character energy β¨
β¨ OPTIONS β¨
-i[<extension>]β edits the file(s) in place π«Ά. if you give it an extension (and there is no space between-iand the extension, okay? none. zero. zip.) then the original file gets backed-up with that extension. the rules for the extension are the same as Perl's (seeperldoc perlrun): if the extension includes no*then it is appended to the original file name; if the extension does contain one or more*characters, then each*is replaced with the current filename. slay.-s <style>β the style to use for pretty printing:none,nsgmls,nice,indented,record, orrecord_c(go check theXML::Twigdocs for the exact description of those styles, i'm just the messenger π). default isindented, because of course it is.-p <tag(s)>β preserves white spaces in tags. you can stack several-poptions or just quote the tags if you need more than one. whatever vibes, bestie π-e <encoding>β useXML::Twigoutput_encoding(based onText::IconvorUnicode::Map8andUnicode::String) to set the output encoding. by default the original encoding is preserved, no notes. if you use this option the XML declaration is updated (and created if there was none) β¨
make sure that the encoding is supported by the parser you use if you want to be able to process the pretty_printed file (XML::Parserdoes not supportlatin1for example, you have to useiso-8859-1). fr fr, this one bites people.
-lβ loads the documents in memory instead of outputting them as they are being parsed. this prevents a bug (see BUGS) but uses more memory. trade-offs, babe π-f <file>β read the list of files to process from<file>, one per line π-vβ verbose (list the current file being processed). she's chatty and we love her π£οΈ--β stop argument processing (to process files that start with-) π-hβ display help. bestie behaviour πββοΈ
π 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
look at her go ππ every single one of these is a serve.
π BUGS π
okay so here's the tea. elements with mixed content that start with an embedded element get an extra \n. not me exposing the flawβ
<elt><b>b</b>toto<b>bold</b></elt>
will be output as
<elt>
<b>b</b>toto<b>bold</b></elt>
using the -l option solves this bug (but uses more memory). so like, pick your struggle π«
π TODO π
- update
XML::Twigto useEncodewith perl5.8.0β manifesting this one for her πβ¨
π AUTHOR π
Michel Rodriguez <mirod@xmltwig.com> β the icon, the legend, the moment π
perl v5.40.1 π¦ 2025-12-18 π β and that's the whole page bestie, go forth and pretty-print, you're gonna eat π β¨π«Ά
π¦ where this page comes from
- ubuntu resolute: xml-twig-tools 1:3.54-1build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: xml-twig-tools 1:3.54-1build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms