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

Could be either Keyword or map. Order of the attributes are preserved in case of Keyword

The elements of Enumerable should be of type fragment/0

Types

@type attrs() :: map() | Keyword.t() | [{binary(), binary()}]

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

@type fragment() :: [tuple() | fragment()]

Functions

@spec cdata(String.t()) :: fragment()
@spec comment(String.t()) :: fragment()
@spec content(String.t()) :: fragment()
Link to this function

declaration(attrs \\ [version: "1.0", encoding: "UTF-8"])

View Source
@spec declaration(attrs()) :: fragment()
Link to this function

doctype(root_name, declaration)

View Source
@spec doctype(String.t(), String.t()) :: fragment()
@spec element(String.t(), body()) :: fragment()
Link to this function

element(name, attrs, body)

View Source
@spec element(String.t(), attrs(), body()) :: fragment()
Link to this function

empty_element(name, attrs \\ %{})

View Source
@spec empty_element(String.t(), attrs()) :: fragment()
Link to this function

processing_instruction(name, attrs \\ %{})

View Source
@spec processing_instruction(String.t(), attrs()) :: fragment()
Link to this function

stream!(nodes, options \\ [])

View Source
@spec stream!(fragment(), Keyword.t()) :: Enumerable.t()

Creates a xml document stream.

Options