gws.lib.xmlx.util

Value conversion and escaping for XML output.

Source code: gws.lib.xmlx.util

Module Contents

gws.lib.xmlx.util.atom_to_string(s) → tuple[str, bool]

Convert a primitive value to a string for XML output.

None becomes an empty string, numbers and booleans are lowercased (true, false), datetimes and dates are written in ISO format.

Parameters:

s – The value.

Returns:

A tuple of the string and a flag that is False if the value is not a primitive value.

gws.lib.xmlx.util.escape_attribute(s: str) → str

Escape a string for a double-quoted XML attribute value.

Escapes &, ", <, >, tabs and line breaks.

Parameters:

s – The value.

Returns:

The escaped value.

gws.lib.xmlx.util.escape_text(s: str) → str

Escape &, < and > for XML text content.

Parameters:

s – The text.

Returns:

The escaped text.