RustyXML.Partial (RustyXML v0.2.3)

Copy Markdown View Source

Incremental XML parsing for scenarios where the complete document is not available upfront (e.g., socket streams, chunked HTTP).

Drop-in replacement for Saxy.Partial.

Example

{:ok, partial} = RustyXML.Partial.new(MyHandler, initial_state)

{:cont, partial} = RustyXML.Partial.parse(partial, "<root>")
{:cont, partial} = RustyXML.Partial.parse(partial, "<item/>")
{:cont, partial} = RustyXML.Partial.parse(partial, "</root>")

{:ok, final_state} = RustyXML.Partial.terminate(partial)

Summary

Functions

Get the current handler state without terminating.

Create a new partial parser.

Feed a chunk of XML data to the parser.

Terminate parsing and get the final state.

Types

t()

@type t() :: %RustyXML.Partial{
  handler: module(),
  opts: keyword(),
  parser: RustyXML.Native.parser_ref(),
  started: boolean(),
  state: any()
}

Functions

get_state(partial)

@spec get_state(t()) :: any()

Get the current handler state without terminating.

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

@spec new(module(), any(), keyword()) :: {:ok, t()}

Create a new partial parser.

parse(partial, chunk)

@spec parse(t(), binary()) :: {:cont, t()} | {:halt, any()} | {:error, any()}

Feed a chunk of XML data to the parser.

Returns:

  • {:cont, partial} — more data expected
  • {:halt, state} — handler returned {:stop, state}
  • {:error, reason} — parse error

terminate(partial)

@spec terminate(t()) :: {:ok, any()} | {:error, any()}

Terminate parsing and get the final state.

Sends :end_document to the handler.