ExEssentials.XML (ExEssentials v0.4.2)

View Source

Utility module that wraps and extends Saxy.XML to provide a convenient and safe interface for building XML documents.

This module reexports key functions from Saxy.XML such as element/3, empty_element/2, characters/1, and others, so you can import ExEssentials.XML and use them directly.

It also provides element_sanitize/3, a drop-in replacement for element/3 that automatically escapes special characters in text nodes to ensure well-formed XML output.

Example:

import ExEssentials.XML

element_sanitize("Example", [], ["Some & unsafe < XML > text"])

Summary

Functions

cdata(content)

@spec cdata(text :: term()) :: Saxy.XML.cdata()

See Saxy.XML.cdata/1.

characters(content)

@spec characters(text :: term()) :: Saxy.XML.characters()

See Saxy.XML.characters/1.

comment(content)

@spec comment(text :: term()) :: Saxy.XML.comment()

See Saxy.XML.comment/1.

element(name, attrs, children)

@spec element(
  name :: term(),
  attributes :: [{key :: term(), value :: term()}],
  children :: term()
) ::
  Saxy.XML.element()

See Saxy.XML.element/3.

element_sanitize(name, attrs, children)

@spec element_sanitize(term(), [{term(), term()}], term()) :: Saxy.XML.element()

Builds a sanitized XML element ensuring all text nodes are properly escaped.

This function is a safe replacement for Saxy.XML.element/3 that automatically escapes special characters (&, <, >, ", ') in text nodes to produce well-formed XML.

Examples

iex> import ExEssentials.XML
iex> element_sanitize("note", [], ["<hello> & 'world'"])
{"note", [], ["&lt;hello&gt; &amp; &apos;world&apos;"]}

empty_element(name, attrs)

@spec empty_element(name :: term(), attributes :: [{key :: term(), value :: term()}]) ::
  Saxy.XML.element()

See Saxy.XML.empty_element/2.

processing_instruction(name, instruction)

@spec processing_instruction(name :: String.t(), instruction :: String.t()) ::
  Saxy.XML.processing_instruction()

See Saxy.XML.processing_instruction/2.

reference(character_type, value)

@spec reference(character_type :: :entity | :hexadecimal | :decimal, value :: term()) ::
  Saxy.XML.ref()

See Saxy.XML.reference/2.