---
name: "xo_attr"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/xo_attr"
---

# xo\_attr(3)

Add attribute name/value pairs to formatted output

## NAME

**xo\_attr**, **xo\_attr\_h**, **xo\_attr\_hv** – Add attribute name/value pairs to formatted output

## LIBRARY

library “libxo”

## SYNOPSIS

**#include \<libxo/xo.h\>**

*xo\_ssize\_t*\

**xo\_attr**(*const char \*name*, *const char \*fmt*, *...*);

*xo\_ssize\_t*\

**xo\_attr\_h**(*xo\_handle\_t \*handle*, *const char \*name, const char \*fmt*, *...*);

*xo\_ssize\_t*\

**xo\_attr\_hv**(*xo\_handle\_t \*handle*, *const char \*name*, *const char \*fmt*, *va\_list vap*);

## DESCRIPTION

The **xo\_attr**() function emits attributes for the XML output style.  The attribute value is recorded in the *handle* and is attached to the next field that is emitted via a [xo\_emit(3)](/xo_emit/3.md) call.

The *name* parameter give the name of the attribute to be encoded.  The *fmt* parameter gives a printf-style format string used to format the value of the attribute using any remaining arguments, or the *vap* parameter as passed to **xo\_attr\_hv**().

```
    EXAMPLE:
      xo_attr("seconds", "%ld", (unsigned long) login_time);
      struct tm *tmp = localtime(login_time);
      strftime(buf, sizeof(buf), "%R", tmp);
      xo_emit("Logged in at {:login-time}\n", buf);
    XML:
        <login-time seconds="1408336270">00:14</login-time>
```

Since attributes are only emitted in XML, their use should be limited to meta-data and additional or redundant representations of data already emitted in other form.

## SEE ALSO

[xo\_emit(3)](/xo_emit/3.md), [libxo(3)](/libxo/3.md)

## HISTORY

The **libxo** library first appeared in FreeBSD 11.0.

## AUTHORS

**libxo** was written by Phil Shafer ⟨*phil@freebsd.org*⟩.
