View Source Saxy.Partial (Saxy v1.6.0)

Supports parsing an XML document partially. This module is useful when the XML document cannot be turned into a Stream e.g over sockets.

Example

iex> {:ok, partial} = Saxy.Partial.new(StackHandler, [])
iex> {:cont, partial} = Saxy.Partial.parse(partial, "<foo>")
iex> {:cont, partial} = Saxy.Partial.parse(partial, "</foo>")
iex> Saxy.Partial.terminate(partial)
{:ok,
 [
   end_document: {},
   end_element: "foo",
   start_element: {"foo", []},
   start_document: []
 ]}

Summary

Functions

Obtain the state set by the user.

Builds up a Saxy.Partial, which can be used for later parsing.

Continue parsing next chunk of the document with a partial.

Same as partial/2, but continue previous parsing with a new, provided state as the third argument instead of the previous accumulated state.

Terminates the XML document parsing.

Types

Functions

@spec get_state(partial :: t()) :: state :: term()

Obtain the state set by the user.

Link to this function

new(handler, initial_state, options \\ [])

View Source
@spec new(
  handler :: module(),
  initial_state :: term(),
  options :: Keyword.t()
) :: {:ok, partial :: t()} | {:error, exception :: Saxy.ParseError.t()}

Builds up a Saxy.Partial, which can be used for later parsing.

@spec parse(
  partial :: t(),
  data :: binary()
) ::
  {:cont, partial :: t()}
  | {:halt, state :: term()}
  | {:halt, state :: term(), rest :: binary()}
  | {:error, exception :: Saxy.ParseError.t()}

Continue parsing next chunk of the document with a partial.

This function can return in 3 ways:

  • {:cont, partial} - The parsing process has not been terminated.
  • {:halt, user_state} - The parsing process has been terminated, usually because of parser stopping.
  • {:halt, user_state, rest} - The parsing process has been terminated, usually because of parser halting.
  • {:error, exception} - The parsing process has erred.
Link to this function

parse(partial, data, user_state)

View Source
@spec parse(
  partial :: t(),
  data :: binary(),
  user_state :: term()
) ::
  {:cont, partial :: t()}
  | {:halt, state :: term()}
  | {:halt, state :: term(), rest :: binary()}
  | {:error, exception :: Saxy.ParseError.t()}

Same as partial/2, but continue previous parsing with a new, provided state as the third argument instead of the previous accumulated state.

i.e. Saxy.Partial.parse(partial, binary, new_state) # coninue previous partial with a new state

This function can return in 3 ways:

  • {:cont, partial} - The parsing process has not been terminated.
  • {:halt, user_state} - The parsing process has been terminated, usually because of parser stopping.
  • {:halt, user_state, rest} - The parsing process has been terminated, usually because of parser halting.
  • {:error, exception} - The parsing process has erred.
@spec terminate(partial :: t()) ::
  {:ok, state :: term()} | {:error, exception :: Saxy.ParseError.t()}

Terminates the XML document parsing.