SweetXml.stream

You're seeing just the function stream, go back to SweetXml module for more information.
Link to this function

stream(doc, options_callback)

View Source

Will be later deprecated in favor of stream!/2.

Create an element stream from a XML doc.

This is a lower level API compared to SweetXml.stream_tags. You can use the options_callback argument to get fine control of what data to be streamed.

  • doc is an enumerable, data will be pulled during the result stream enumeration. e.g. File.stream!("some_file.xml")
  • options_callback is an anonymous function fn emit -> (xmerl_opts | opts) use it to define your :xmerl callbacks and put data into the stream using emit.(elem) in the callbacks. More details are available with parse/2.

For example, here you define a stream of all xmlElement :

iex> import Record
iex> doc = ["<h1", "><a>Som", "e linked title</a><a>other</a></h1>"]
iex> SweetXml.stream(doc, fn emit ->
...>   [
...>     hook_fun: fn
...>       entity, xstate when is_record(entity, :xmlElement)->
...>         emit.(entity)
...>         {entity, xstate}
...>       entity, xstate ->
...>         {entity,xstate}
...>     end
...>   ]
...> end) |> Enum.count
3