{xmlfield:tags:field_id}

Description

Wraps an item field value in an XML element, for building XML or RSS export feeds from item content. The first parameter is the tag (or two space-separated names: an outer wrapper tag and the inner element tag). The second parameter is a field id of the slice of the current item - or any AA expression/alias, which is then resolved and wrapped as-is. xmlfield needs a current item: with no item in context it returns nothing. A multi-value field repeats the element once per value; a multilingual field adds a lang attribute per translation (lang="cs", lang="en"); a field that offers a formatter choice adds a format attribute (format="plain" or format="html"). For a field id, empty values are skipped and the outer wrapper is emitted only when at least one inner element exists; an expression or alias always produces exactly one element, even an empty one. Element content is XML-escaped. Bind a specific item with the item expression, deferring xmlfield so it runs in the context of that item: see the examples. The examples wrap the call in safe so that the generated tags are shown on this page as text; in a feed template you write xmlfield alone.

Parameters

tags required default (empty)

The XML element name to wrap the value in. Give one name for a plain element, or two space-separated names to add an outer wrapper: an outer-tag plus an inner-tag. With two names every value becomes an inner element and the whole set is wrapped once in the outer tag (the outer tag is emitted only when there is at least one value).

field_id required default (empty)

Which field of the slice of the current item to read, e.g. headline........ or category........ . You may instead pass any AA expression or alias (for example _#NUMBER__ or literal text); when it is not a field id it is resolved and wrapped as-is, without the per-value, format or lang handling that real fields get.

Examples

test[{item:5726c2c6b035d7aab450d1794e9e90d7:{({safe:{xmlfield:name:headline........}})}}]
Expected[<name>Gamma</name>]
Actual[<name>Gamma</name>]
The everyday use: wrap one item's field in an XML element. Bind the item with the item expression and defer xmlfield with the (...) braces so it runs in that item's context; a bare xmlfield reads whatever item is currently rendering.
test[{item:5726c2c6b035d7aab450d1794e9e90d7:{({xmlfield:tag:edit_note.......})}}]
Expected[]
Actual[]
An empty field produces no element at all - xmlfield skips empty values. Here the item's edit_note field is blank, so the result is empty.
test{item:5726c2c6b035d7aab450d1794e9e90d7:{({safe:{xmlfield:colors color:abstract........}})}}
Expected<colors><color format="plain">red</color></colors>
Actual<colors><color format="plain">red</color></colors>
Two space-separated names give an outer wrapper and an inner element: outer-tag then inner-tag. Each value becomes an inner element and the whole set is wrapped once. The format attribute appears because this field offers a plain/html formatter choice.
test[{item:5726c2c6b035d7aab450d1794e9e90d7:{({xmlfield:colors color:edit_note.......})}}]
Expected[]
Actual[]
The outer wrapper is emitted only when there is at least one inner element. With an empty source field, both the inner element and the outer wrapper are suppressed - the result is empty, not an empty pair of tags.
test[{item:5726c2c6b035d7aab450d1794e9e90d7:{({safe:{xmlfield:body:full_text.......}})}}]
Expected[<body format="plain">Gamma contains color data: red green blue. Used for string tests.</body>]
Actual[<body format="plain">Gamma contains color data: red green blue. Used for string tests.</body>]
When a field lets the editor pick a formatter (plain or html), xmlfield records that choice as a format attribute on the element. The body field here is stored plain, so format=plain.
virtual{item:00000000000000000000000000000000:{({xmlfield:name:headline........})}}
Expected(for a multilingual field - none in the test data: <name lang="cs">Jan</name><name lang="en">John</name>)
For a multilingual field, xmlfield repeats the element once per translation and tags each with a lang attribute. The frozen test slice is single-language and the item id here is a placeholder, so the live result is empty; the expected output below shows the shape you get on a real multilingual slice.
test[{item:5726c2c6b035d7aab450d1794e9e90d7:{({safe:{xmlfield:n:_#NUMBER__}})}}]
Expected[<n>100</n>]
Actual[<n>100</n>]
The second parameter does not have to be a field id. Any AA expression or alias is resolved and wrapped as-is. Here _#NUMBER__ is the item's integer alias; because it is not a slice field, no format or lang handling is applied.
test{item:5726c2c6b035d7aab450d1794e9e90d7:{({safe:{xmlfield:title:headline........}{xmlfield:summary:abstract........}})}}
Expected<title>Gamma</title><summary format="plain">red</summary>
Actual<title>Gamma</title><summary format="plain">red</summary>
The real-world pattern: inside an item view or export template the current item is already in context, so you list one xmlfield per field you want in the feed. Each emits one element and empty fields drop out. Here two fields of one item are bound to show the combined output; the summary field carries a format attribute because it offers a formatter choice.
test[{item:5726c2c6b035d7aab450d1794e9e90d7:{({safe:{xmlfield:w n:{ifset::nothing}}})}}]
Expected[<w><n></n></w>]
Actual[<w><n></n></w>]
Only real fields have their empty values skipped. When the second parameter is an expression that comes out empty, xmlfield still writes one empty element, and the outer wrapper with it. Wrapped in safe so the page shows the markup as text.