{safexml:text}

Description

Escapes the five XML special characters in text so the result is safe to drop into an XML or RSS document, both inside an element and inside a quoted attribute. The ampersand becomes &, the less-than sign becomes <, the greater-than sign becomes >, the double quote becomes ", and the single quote (apostrophe) becomes '. Every other character, including UTF-8 letters and accents, passes through unchanged. Empty input gives empty output. Use it whenever you place raw item content into a hand-built XML or RSS template, because AA does not auto-escape there. The companion command safe does the same job for HTML output (it differs mainly in charset and a few edge cases), and xmlfield wraps a value in a full XML element for you. One trap: AA splits parameters on the colon, so a value containing a colon must escape it as hash-colon or everything after the colon is dropped.

Parameters

text required default (empty)

The text to escape. Any string - typically an item field value you are emitting into an XML or RSS template. The five XML special characters are replaced with their entities; everything else, including UTF-8 letters and accents, is left untouched.

Examples

virtual{safexml:News#: A & B}
ExpectedNews: A & B
ActualNews: A & B
The fix for the colon trap: write the colon as hash-colon so AA does not treat it as a parameter break. Now the whole string is escaped and the colon is preserved in the output.
test{safexml:Annual report 2025}
ExpectedAnnual report 2025
ActualAnnual report 2025
Text with none of the five special characters is returned exactly as given - no encoding happens.
test[{safexml:}]
Expected[]
Actual[]
With no text the result is empty. The brackets here are literal, only to make the empty result visible.
virtual{safexml:Health & Safety}
ExpectedHealth & Safety
ActualHealth & Safety
The ampersand is the most common XML-breaking character. safexml turns it into the & entity so the document stays well-formed.
virtual{safexml:<title>}
Expected&lt;title&gt;
Actual<title>
Less-than and greater-than become &lt; and &gt;, so a literal tag-looking string in your data is not mistaken for real markup.
virtual{safexml:say "hello"}
Expectedsay &quot;hello&quot;
Actualsay "hello"
The double quote becomes &quot;. This is what makes a value safe to place inside a double-quoted XML attribute.
virtual{safexml:it's here}
Expectedit&apos;s here
Actualit's here
The apostrophe (single quote) becomes the XML entity &apos;. This is the main difference from the HTML-oriented safe command.
virtual<title>{safexml:Tom & Jerry "Best of"}</title>
Expected<title>Tom &amp; Jerry &quot;Best of&quot;</title>
ActualTom & Jerry "Best of"
The everyday use: wrap a field value before placing it inside a hand-built RSS or XML element, so an ampersand or quote in the data cannot break the feed. In a real template the value comes from a field getter such as the headline. Note safexml takes only the text up to the first colon, so a value that contains a colon needs the colon escaped (see the colon example below).
virtual<item label="{safexml:R&D <draft>}" />
Expected<item label="R&amp;D &lt;draft&gt;" />
Actual
Escaping a value destined for a quoted attribute. Both the ampersand and the angle brackets are encoded, so the attribute and the surrounding element stay well-formed.
test{safexml:News: A & B}
ExpectedNews
ActualNews
Trap. safexml reads only one parameter, and AA splits parameters on the colon, so any text after the first colon is silently dropped. Here only the part before the colon survives. To keep a literal colon, escape it as a hash followed by a colon (the same trick used in http#://), which makes safexml see the whole string. This matters most for AI-generated templates feeding free-text values that may contain colons.