xml::escape

Function escape_str_attribute

Source
pub fn escape_str_attribute(s: &str) -> Cow<'_, str>
Expand description

Performs escaping of common XML characters inside an attribute value.

This function replaces several important markup characters with their entity equivalents:

  • <&lt;
  • >&gt;
  • "&quot;
  • '&apos;
  • &&amp;

The following characters are escaped so that attributes are printed on a single line:

  • \n&#xA;
  • \r&#xD;

The resulting string is safe to use inside XML attribute values or in PCDATA sections.

Does not perform allocations if the given string does not contain escapable characters.