brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: xmllint makes a wall of XML readable and checks that it parses

Tools
~/tips/tip-tools-xmllint-format-check

xmllint --format feed.xml

Indent XML for reading and find where a broken document goes wrong.

APIs and config exports love to hand you XML as one endless line. xmllint sorts that out, and it is already on macOS and available on most Linux distributions.

xmllint --format feed.xml

The indented version is printed to the screen and the original stays untouched. It reads from a pipe when you give - as the name:

curl -s https://example.com/sitemap.xml | xmllint --format -

The other thing I use it for is checking whether a file is well formed at all:

xmllint --noout config.xml

Silence means it parsed. Otherwise you get the line number and the reason, such as an opening and ending tag mismatch, with a marker under the spot, and a non zero exit status. That is far quicker than staring at a settings file that an app refuses to load.

Run the check before you restart a service whose configuration you edited by hand.

Well formed only means the syntax is right. A misspelled element name passes happily, since checking against a schema is a separate job. Don’t redirect the output onto the input file, or you’ll end up with an empty one. And on some Linux systems you need to install the libxml2 utilities first.

Further reading: xmllint manual

More Tools tips shuf -n 3 films.txt pdftotext -layout invoice.pdf invoice.txt qrencode -t ANSIUTF8 'https://example.com/a/long/path?id=12345' where python ffprobe -v error -show_entries format=duration -of default=nw=1:nk=1 input.mp4 All Tools tips (14) All topics

Link