View Source exml_stream (exml v4.1.0)

XML stream parser

Summary

Types

#parser{} record. Keeps track of unparsed buffers.

Parser options

#xmlstreamstart{} record.

#xmlstreamend{} record.

Functions

Free a parser

Creates a new parser. See parser_opt/0 for configuration.

Makes a parser parse input.

Resets the parser's buffers

Types

element/0

-type element() :: exml:element() | start() | stop().

One of exml:element/0, start/0, or stop/0.

parser/0

-type parser() :: #parser{event_parser :: term(), buffer :: [binary()]}.

#parser{} record. Keeps track of unparsed buffers.

parser_opt/0

-type parser_opt() :: {infinite_stream, boolean()} | {max_element_size, non_neg_integer()}.

Parser options

  • infinite_stream: No distinct start/0 or stop/0, only #xmlel{} will be returned.
  • max_element_size: Specifies maximum byte size of any parsed XML element. The only exception is the "stream start" element, for which only the size of the opening tag is limited.

start/0

-type start() :: #xmlstreamstart{name :: binary(), attrs :: exml:attrs()}.

#xmlstreamstart{} record.

stop/0

-type stop() :: #xmlstreamend{name :: binary()}.

#xmlstreamend{} record.

Functions

free_parser(Parser)

-spec free_parser(parser()) -> ok.

Free a parser

Kept for backwards-compatibility, it is a no-op.

new_parser()

-spec new_parser() -> {ok, parser()} | {error, any()}.

See also: new_parser/1.

new_parser(Opts)

-spec new_parser([parser_opt()]) -> {ok, parser()} | {error, any()}.

Creates a new parser. See parser_opt/0 for configuration.

parse(Parser, Input)

-spec parse(parser(), binary()) -> {ok, parser(), [element()]} | {error, Reason :: binary()}.

Makes a parser parse input.

If successful, returns parsed elements and a new parser with updated buffers.

reset_parser(Parser)

-spec reset_parser(parser()) -> {ok, parser()}.

Resets the parser's buffers