ExEssentials.XML (ExEssentials v0.4.2)
View SourceUtility 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
Builds a sanitized XML element ensuring all text nodes are properly escaped.
Functions
@spec cdata(text :: term()) :: Saxy.XML.cdata()
See Saxy.XML.cdata/1
.
@spec characters(text :: term()) :: Saxy.XML.characters()
@spec comment(text :: term()) :: Saxy.XML.comment()
See Saxy.XML.comment/1
.
@spec element( name :: term(), attributes :: [{key :: term(), value :: term()}], children :: term() ) :: Saxy.XML.element()
See Saxy.XML.element/3
.
@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", [], ["<hello> & 'world'"]}
@spec empty_element(name :: term(), attributes :: [{key :: term(), value :: term()}]) :: Saxy.XML.element()
@spec processing_instruction(name :: String.t(), instruction :: String.t()) :: Saxy.XML.processing_instruction()
@spec reference(character_type :: :entity | :hexadecimal | :decimal, value :: term()) :: Saxy.XML.ref()
See Saxy.XML.reference/2
.