Reading side of the SEFAZ XML, on :xmerl.
Safety
The body arrives over the network, so parsing is hardened before :xmerl
sees it. A DTD is rejected outright: SEFAZ never sends one, and accepting it
is what opens both XXE and entity expansion (billion laughs). :xmerl has no
budget for either, so refusing the construct is the defence rather than
limiting it. External fetches are stubbed as a second layer, and a malformed
body is an error rather than a crash — the network is allowed to be hostile.
Encoding
The body is handed to :xmerl as raw bytes, not as a decoded charlist.
SEFAZ declares encoding="utf-8" and its messages are Portuguese — every
rejection carries accents — so :xmerl must do the decoding itself. Passing
already-decoded codepoints makes it decode twice and reject the document.
Scanning is namespace conformant, which is what populates the namespace axis
SefazNfe.XML.C14N needs to canonicalise a subtree for signing.
Reading
text/2 and attribute/3 take a local element name and ignore namespace
prefixes. SEFAZ responses arrive prefixed differently per UF and per service,
and matching on the local name is what keeps one parser working across all of
them.
Summary
Functions
Every element whose local name is name.
Value of attribute attr on the first element named name.
The attributes of element as {name, value}, in document order, without
namespace declarations (xmlns, xmlns:p).
The element children of element, in document order (text is skipped).
The first element whose local name is name, as an :xmerl record.
Text of name as an integer, or nil when absent or not numeric.
Attribute attr on element itself, without searching its descendants.
Text of element itself, without searching its descendants.
Parses body into an :xmerl document.
The namespace URI (nil when there is none) and local name of element.
The text directly inside element, exactly as written: not trimmed, entities
resolved. Descendant elements are not read.
Text content of the first element whose local name is name.
Types
@type doc() :: tuple()
Functions
Every element whose local name is name.
Value of attribute attr on the first element named name.
The attributes of element as {name, value}, in document order, without
namespace declarations (xmlns, xmlns:p).
The element children of element, in document order (text is skipped).
The first element whose local name is name, as an :xmerl record.
Text of name as an integer, or nil when absent or not numeric.
Attribute attr on element itself, without searching its descendants.
Text of element itself, without searching its descendants.
Parses body into an :xmerl document.
Returns {:error, {:xml, :dtd_forbidden}} for a body carrying a DTD and
{:error, {:xml, :malformed}} when :xmerl cannot read it.
The namespace URI (nil when there is none) and local name of element.
The text directly inside element, exactly as written: not trimmed, entities
resolved. Descendant elements are not read.
Text content of the first element whose local name is name.