1XO(1) BSD General Commands Manual XO(1)
2
4 xo — emit formatted output based on format string and arguments
5
7 xo [-options] [argument...]
8
10 The xo utility allows command line access to the functionality of the
11 libxo library. Using xo, shell scripts can emit XML, JSON, or HTML using
12 the same commands that emit text output.
13
14 --close path
15 Close tags for the given path
16
17 -C | --continuation
18 Indicates this output is a continuation of the previous output
19 data and should appear on the same line. This is allows HTML
20 output to be constructed correctly.
21
22 --depth num
23 Set the depth for pretty printing
24
25 --help Display help text
26
27 -H | --html
28 Generate HTML output
29
30 -J | --json
31 Generate JSON output
32
33 --leading-xpath path
34 Add a prefix to generated XPaths (HTML)
35
36 --not-first
37 Indicate that this content is not the first in a series of sib‐
38 ling objects, which is vital information for "JSON" output, which
39 requires a comma between such objects.
40
41 --open path
42 Open tags for the given path
43
44 -p | --pretty
45 Make 'pretty' output (add indent, newlines)
46
47 --style style
48 Generate given style (xml, json, text, html)
49
50 -T | --text
51 Generate text output (the default style)
52
53 --top-warp
54 Indicates the entire object should be placed inside a top-level
55 object wrapper, specifically when generating JSON output.
56
57 --version
58 Display version information
59
60 -W | --warn
61 Display warnings in text on stderr
62
63 --warn-xml
64 Display warnings in xml on stdout
65
66 --wrap path
67 Wrap output in a set of containers
68
69 -X | --xml
70 Generate XML output
71
72 --xpath
73 Add XPath data to HTML output
74
75 The xo utility accepts a format string suitable for xo_emit(3) and a set
76 of zero or more arguments used to supply data for that string.
77
78 In addition, xo accepts any of the libxo options listed in xo_options(7).
79
81 In this example, xo is used to emit the same data encoded in text and
82 then in XML by adding the "-p" (pretty) and "-X" (XML output) flags:
83
84 % xo 'The {:product} is {:status}\n' stereo "in route"
85 The stereo is in route
86 % xo -p -X 'The {:product} is {:status}\n' stereo "in route"
87 <product>stereo</product>
88 <status>in route</status>
89
90 In this example, the output from a xo command is shown in several styles:
91
92 xo "The {k:name} weighs {:weight/%d} pounds.\n" fish 6
93
94 TEXT:
95 The fish weighs 6 pounds.
96 XML:
97 <name>fish</name>
98 <weight>6</weight>
99 JSON:
100 "name": "fish",
101 "weight": 6
102 HTML:
103 <div class="line">
104 <div class="text">The </div>
105 <div class="data" data-tag="name">fish</div>
106 <div class="text"> weighs </div>
107 <div class="data" data-tag="weight">6</div>
108 <div class="text"> pounds.</div>
109 </div>
110
111 The --wrap <path> option can be used to wrap emitted content in a spe‐
112 cific hierarchy. The path is a set of hierarchical names separated by
113 the '/' character.
114
115 xo --wrap top/a/b/c '{:tag}' value
116
117 XML:
118 <top>
119 <a>
120 <b>
121 <c>
122 <tag>value</tag>
123 </c>
124 </b>
125 </a>
126 </top>
127 JSON:
128 "top": {
129 "a": {
130 "b": {
131 "c": {
132 "tag": "value"
133 }
134 }
135 }
136 }
137
138 The --open <path> and --close <path> can be used to emit hierarchical in‐
139 formation without the matching close and open tag. This allows a shell
140 script to emit open tags, data, and then close tags. The --depth option
141 may be used to set the depth for indentation. The --leading-xpath may be
142 used to prepend data to the XPath values used for HTML output style.
143
144 #!/bin/sh
145 xo --open top/data
146 xo --depth 2 '{:tag}' value
147 xo --close top/data
148
149 XML:
150 <top>
151 <data>
152 <tag>value</tag>
153 </data>
154 </top>
155 JSON:
156 "top": {
157 "data": {
158 "tag": "value"
159 }
160 }
161
163 libxo(3), xo_emit(3), xo_options(7)
164
166 The libxo library first appeared in FreeBSD 11.0.
167
169 libxo was written by Phil Shafer <phil@freebsd.org>.
170
171
173 FreeBSD uses libxo version 1.6.0. Complete documentation can be found on
174 github:
175
176 https://juniper.github.io/libxo/1.6.0/html/index.html
177
178 libxo lives on github as:
179
180 https://github.com/Juniper/libxo
181
182 The latest release of libxo is available at:
183
184 https://github.com/Juniper/libxo/releases
185
187 The libxo library was added in FreeBSD 11.0.
188
190 Phil Shafer
191
192BSD December 4, 2014 BSD