Lather.Soap.Elements (lather v1.1.0)

Copy Markdown View Source

Prefix-agnostic access to parsed SOAP documents.

Lather.Xml.Parser keeps namespace prefixes in element names, so the same envelope can arrive as "soap:Envelope", "soapenv:Envelope", "SOAP-ENV:Envelope", "s:Envelope" or plain "Envelope" depending on the peer. The functions here look elements up by local name so callers do not have to enumerate prefixes.

Summary

Functions

Finds the child of map whose local name is local.

Returns the value of the child of map with local name local, or nil.

Walks a path of local names, like get_in/2 but prefix-agnostic and safe against non-map intermediate values.

Returns the local part of a possibly prefixed element name.

Returns the namespace URI declared for element_key's prefix on element (a parsed element map), or nil.

Returns the prefix of an element name, or nil when it has none.

SOAP 1.1 envelope namespace URI.

SOAP 1.2 envelope namespace URI.

Detects the SOAP version of a parsed document from the namespace bound to the Envelope element. Falls back to the fault structure (SOAP 1.2 faults carry Code/Value) and finally to :v1_1.

Functions

find(map, local)

@spec find(any(), String.t()) :: {String.t(), any()} | nil

Finds the child of map whose local name is local.

Returns {key, value} with the actual (possibly prefixed) key, or nil when there is no such child or map is not a map. An exact key match wins over a prefixed one; attribute keys (@...) and #text are never matched.

get(map, local)

@spec get(any(), String.t()) :: any()

Returns the value of the child of map with local name local, or nil.

get_in(value, list)

@spec get_in(any(), [String.t()]) :: any()

Walks a path of local names, like get_in/2 but prefix-agnostic and safe against non-map intermediate values.

Elements.get_in(parsed, ["Envelope", "Body", "Fault"])

local_name(name)

@spec local_name(String.t() | atom()) :: String.t()

Returns the local part of a possibly prefixed element name.

iex> Lather.Soap.Elements.local_name("soapenv:Body")
"Body"
iex> Lather.Soap.Elements.local_name("Body")
"Body"

namespace_of(element_key, element)

@spec namespace_of(String.t(), any()) :: String.t() | nil

Returns the namespace URI declared for element_key's prefix on element (a parsed element map), or nil.

Looks for @xmlns:prefix when the key is prefixed and @xmlns when it is not.

prefix(name)

@spec prefix(String.t() | atom()) :: String.t() | nil

Returns the prefix of an element name, or nil when it has none.

soap_1_1_namespace()

SOAP 1.1 envelope namespace URI.

soap_1_2_namespace()

SOAP 1.2 envelope namespace URI.

soap_version(parsed)

@spec soap_version(map()) :: :v1_1 | :v1_2

Detects the SOAP version of a parsed document from the namespace bound to the Envelope element. Falls back to the fault structure (SOAP 1.2 faults carry Code/Value) and finally to :v1_1.