How can I print an SVG, already scaled to a4 size, from the command line?
I tried using
lpr, but instead the printer just printed out the actual XML of the file, which isn't what I wanted.
Inkscape can convert between various vector graphics formats, including SVG to PDF. Although it's normally a GUI application, it can run in batch mode without an X server available.
inkscape --without-gui --export-pdf=foo.pdf foo.svg lpr foo.pdf
Or if you want to print directly:
inkscape --without-gui --export-pdf=/dev/stdout foo.svg | lpr
Another possibility is the Apache Batik library. However, although there is a command line tool based on that library, Fop, it doesn't seem to have a way to use SVG input, so you'd have to write a bit of glue code in Java.
SVG files, as you noted, are just xml text. Dumping that data straight to the printer is going to get you a bunch of nothing. What you need is a program that can RENDER that data. You say the file is already scaled to A4 size that's just a coordinate space for the scalable vector data. It isn't rendered.
However don't despair! There are lots of programs that can render the data from the command line and some that can even render and print all in one wack. You need to look into command line flags for some heavier weight programs that you might normally expect to get a GUI with.
For example, I know you can use LibreOffice on the command line to open and print a file or convert it to another format. There is a handy command line utility called unoconv that makes the conversion process a lot easier by simplifying all the flags you would have to send.
The Gimp also has some command line flags to open, convert, save and even print. Some of the old standbys like ImageMagick are also able to convert SVG files to rendered images at a given size. I expect other applications like Inkscape are also able to do this.
Once you have an image, it should be easy to print from the command line. If you do this often, you could write a little two line script to convert and print!