Leading me down the garden path today, how to quickly display an XML document … graphically, from the command line?
This doesn’t work:
$ virt-inspector --xml RHEL54.img | firefox -
Creating a temporary file is possible, but ugly.
Then I was tipped off that you can create and pass a data: URI to Firefox.
There is no existing command line tool to generate data URIs, but we can write one in 3 lines of shell script:
#!/bin/sh - echo -n data:$1\; uuencode -m notused | tail -n +2 | tr -d '\n'
$ cat > /tmp/test.html <b>Hello,</b> <i>world!</i> $ datauri text/html < /tmp/test.html data:text/html;PGI+SGVsbG8sPC9iPgo8aT53b3JsZCE8L2k+Cg======
This also doesn’t work. There are two problems: the XML generated by virt-inspector is too long for a data URI, and in any case Firefox seems to ignore the data URI although I’m sure I’m constructing it correctly. Maybe it’s a security or configuration issue?
Well, good idea, but let’s go back to the temporary file idea. Bash process substitution might have worked:
$ firefox <(virt-inspector --xml RHEL54.img)
but Firefox’s frankly stupid session management crap gets in the way because this command expands to something like:
$ firefox /proc/self/fd/123
and the new firefox process passes the non-portable /proc/self path to the currently running instance of Firefox which doesn’t have the same view of /proc/self.
So we are finally left with:
$ firefox $(f=`mktemp -u`; virt-inspector --xml RHEL54.img > $f.xml; echo $f.xml)
which is fugly and unsafe.
If only there was a less insane tool to display XML, but being XML I guess insane goes with the territory.
3 responses to “Display an XML doc from the command line”
Have you considered using something like cwm to translate it into n3? n3 is generally human readable if done right and is a simple transformation of xml with no data loss.
http://www.w3.org/2001/02pd/ might interest you also. This includes an example of how you munge xml into graphviz dots and arrows diagrams.
Sean, not really sure I understand how n3 helps (or what n3 is).