View Source Saxaboom.Mapper (Saxaboom v0.1.1)

The main user interface for defining mapping definitions.

Saxaboom.Mapper exposes a micro-DSL for describing the expected structure of a given document. There are three components to the Saxaboom.Mapper interface:

  • document: a directive describing the "envelope" of the incoming document (read: the whole document). This exposes the internal DSL.
  • element: a directive to match zero to one element and collect into a single struct field
  • elements: a directive to match zero to N elements and collect in a list in the order they are encountered

Summary

Functions

Begins the definition of a "document", that is, a section of parseable content.

Defines a structure field that can match against 0 or 1 elements in the given document.

Defines a structure field that can match against 0 or N elements in the given document. The list will be parsed and extracted in document order. Defaults to an empty list.

Functions

Link to this macro

document(list)

View Source (macro)

Begins the definition of a "document", that is, a section of parseable content.

Link to this macro

element(name, opts \\ [])

View Source (macro)

Defines a structure field that can match against 0 or 1 elements in the given document.

Arguments:

  • name is the name of the tag to match against, case sensitive

Options:

  • :as provides the name to be used on the struct when parsing, defaults to the name of the tag
  • :value identifies the property to extract from the tag. Can be an attribute name, defaults to the text content of the node
  • :with is a keyword list of attributes and expected attribute values. The :with must perfectly match against a subset of the node attributes
  • :cast is a symbol or a user-defined function to transform the extracted :value, see Saxaboom.Utils.Caster for more details.
  • :into is another mapper or type that implements the Saxaboom.ElementCollectable protocol. Child nodes will be parsed into this structure until the parser has encountered the closing tag of the node that began the :into.
  • :default is the default value of the node, if no tags are parsed. nil by default
Link to this macro

elements(name, opts \\ [])

View Source (macro)

Defines a structure field that can match against 0 or N elements in the given document. The list will be parsed and extracted in document order. Defaults to an empty list.

Arguments:

  • name is the name of the tag to match against, case sensitive

Options:

  • :as provides the name to be used on the struct when parsing, defaults to the name of the tag
  • :value identifies the property to extract from the tag. Can be an attribute name, defaults to the text content of the node
  • :with is a keyword list of attributes and expected attribute values. The :with must perfectly match against a subset of the node attributes
  • :cast is a symbol or a user-defined function to transform the extracted :value, see Saxaboom.Utils.Caster for more details.
  • :into is another mapper or type that implements the Saxaboom.ElementCollectable protocol. Child nodes will be parsed into this structure until the parser has encountered the closing tag of the node that began the :into.