View Source XmlStream (xml_stream v0.4.0)
This module provides primitives to build XML document as a Stream
Example
import XmlStream
rows = Stream.map(1..1000, fn i ->
cells = Stream.map(1..40, fn j ->
element("cell", %{row: to_string(i), column: to_string(j)}, content(to_string(i)))
end)
element("row", cells)
end)
stream!([declaration(), element("sheet", rows)], printer: XmlStream.Printer.Ugly)
|> Stream.into(File.stream!("sheet.xml"))
|> Stream.run
The body of an element could be either a eager Enumerable
or a
lazy one built via Stream
module. The primitive functions like
element/3
, content/1
are used to build a tree structure where
some nodes are not fully evaluated (child nodes could a
stream). stream!/2
does a depth first traversal of the tree and
runs the stream as necessary when it encounters one and returns a
new stream of element type iodata
Summary
Types
The elements of Enumerable
should be of type fragment/0
Functions
Creates a xml document stream.
Types
Could be either Keyword
or map
. Order of the attributes are
preserved in case of Keyword
@type body() :: fragment() | Enumerable.t()
The elements of Enumerable
should be of type fragment/0
Functions
@spec stream!(fragment(), Keyword.t()) :: Enumerable.t()
Creates a xml document stream.
Options
:printer
(module) - The printer that should be used for formatting Available options areXmlStream.Printer.Pretty
andXmlStream.Printer.Ugly
:indent_with
(string) - The string that should be used for indentation. Defaults to"\t"
.