How can I highlight XML from stdin (e.g. piped from xmllint --format) to stdout?

I know how to get highlighting working in nano and view, but is there something that just outputs to stdout and exits?

What I'd link to do is just type something like

xmllint --format xmlfile.xml | some-highlighter

or maybe, for big files

xmllint --format xmlfile.xml | some-highlighter | less

and get pretty output.

link|improve this question

50% accept rate
feedback

3 Answers

up vote 1 down vote accepted

Supercat and grcat (grc) can do piped syntax highlighting. You'll probably have to make or find configuration files for XML. They are both available in the Ubuntu repositories as well as at the links provided.

Pygmentize has XML highlighting included. It's available as "python-pygments" in the Ubuntu repositories or by using easy_install Pygments.

xmllint --format xmlfile.xml | pygmentize -l xml | less
link|improve this answer
Pygmentize did the trick for me, although, at least on OS X, I had to give it the option -O encoding=UTF-8 to make it work on xmllint's output. Thanks! – Sietse Sep 29 '10 at 12:38
feedback

This is how you do it using GNU source-highlight and less:

source-highlight -i /tmp/foo.xml -o STDOUT -f esc | less -r
link|improve this answer
feedback

I found highlight in Homebrew for OSX, and I'm sure it's available in the Ubuntu repository. It does highlighting and output to a number of formats, including terminal output.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.