XML Output: libxo - provide single API to output TXT, XML, JSON and HTML

Phil Shafer phil at juniper.net
Mon Aug 18 13:11:51 UTC 2014


Stefan Esser writes:
>Is it possible to introduce a "xo" command which takes a command
>line as an argument (in the same way as e.g. "time").  A sample
>usage could be "xo ls -s", which should invoke "ls -l" with its
>output converted to XML (and "xo -json ls -l" could produce JSON
>output).

I've implemented the "--libxo" option, in a function called
xo_parse_args(), that it called before getopt* and processes and
removes libxo options.  See the example on:

http://juniper.github.io/libxo/libxo-manual.html

FWIW, there's an "xo" command packaged with libxo that perform
similar to the printf(1) command:

% xo --wrap top/data 'My {:pet} is {:age} years old\n' dog 2
My dog is 2 years old
% xo --xml --pretty --wrap top/data 'My {:pet} is {:age} years old\n' dog 2
<top>
  <data>
    <pet>dog</pet>
    <age>2</age>
  </data>
</top>

Thanks,
 Phil


More information about the freebsd-arch mailing list