Changeset View
Changeset View
Standalone View
Standalone View
contrib/libxo/libxo/xo_open_list.3
Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | |||||
A call is needed to | A call is needed to | ||||
open and close the list, while a distinct call is needed to open and | open and close the list, while a distinct call is needed to open and | ||||
close each instance of the list: | close each instance of the list: | ||||
.Bd -literal -offset indent -compact | .Bd -literal -offset indent -compact | ||||
xo_open_list("item"); | xo_open_list("item"); | ||||
for (ip = list; ip->i_title; ip++) { | for (ip = list; ip->i_title; ip++) { | ||||
xo_open_instance("item"); | xo_open_instance("item"); | ||||
xo_emit("{L:Item} '{:name/%s}':\n", ip->i_title); | xo_emit("{L:Item} '{:name/%s}':\\n", ip->i_title); | ||||
xo_close_instance("item"); | xo_close_instance("item"); | ||||
} | } | ||||
xo_close_list("item"); | xo_close_list("item"); | ||||
.Ed | .Ed | ||||
Getting the list and instance calls correct is critical to the proper | Getting the list and instance calls correct is critical to the proper | ||||
generation of XML and JSON data. | generation of XML and JSON data. | ||||
.Pp | .Pp | ||||
.Bd -literal -offset indent -compact | .Bd -literal -offset indent -compact | ||||
EXAMPLE: | EXAMPLE: | ||||
xo_open_list("user"); | xo_open_list("user"); | ||||
for (i = 0; i < num_users; i++) { | for (i = 0; i < num_users; i++) { | ||||
xo_open_instance("user"); | xo_open_instance("user"); | ||||
xo_emit("{k:name}:{:uid/%u}:{:gid/%u}:{:home}\n", | xo_emit("{k:name}:{:uid/%u}:{:gid/%u}:{:home}\\n", | ||||
pw[i].pw_name, pw[i].pw_uid, | pw[i].pw_name, pw[i].pw_uid, | ||||
pw[i].pw_gid, pw[i].pw_dir); | pw[i].pw_gid, pw[i].pw_dir); | ||||
xo_close_instance("user"); | xo_close_instance("user"); | ||||
} | } | ||||
xo_close_list("user"); | xo_close_list("user"); | ||||
TEXT: | TEXT: | ||||
phil:1001:1001:/home/phil | phil:1001:1001:/home/phil | ||||
pallavi:1002:1002:/home/pallavi | pallavi:1002:1002:/home/pallavi | ||||
Show All 30 Lines | |||||
.Sh LEAF LISTS | .Sh LEAF LISTS | ||||
In contrast to a list of instances, a "leaf list" is list of simple | In contrast to a list of instances, a "leaf list" is list of simple | ||||
values. | values. | ||||
To emit a leaf list, call the | To emit a leaf list, call the | ||||
.Fn xo_emit | .Fn xo_emit | ||||
function using the ""l"" modifier: | function using the ""l"" modifier: | ||||
.Bd -literal -offset indent -compact | .Bd -literal -offset indent -compact | ||||
for (ip = list; ip->i_title; ip++) { | for (ip = list; ip->i_title; ip++) { | ||||
xo_emit("{Lwc:Item}{l:item}\n", ip->i_title); | xo_emit("{Lwc:Item}{l:item}\\n", ip->i_title); | ||||
} | } | ||||
.Ed | .Ed | ||||
.Pp | .Pp | ||||
The name of the field must match the name of the leaf list. | The name of the field must match the name of the leaf list. | ||||
.Pp | .Pp | ||||
In JSON, leaf lists are rendered as arrays of values. In XML, they | In JSON, leaf lists are rendered as arrays of values. In XML, they | ||||
are rendered as multiple leaf elements. | are rendered as multiple leaf elements. | ||||
.Bd -literal -offset indent -compact | .Bd -literal -offset indent -compact | ||||
Show All 19 Lines |