Module genx

A safe XML generation library. Genx is a C library by Tim Bray for generating well-formed XML. This is a simple Lua binding.

Functions

document:attribute (key, value) Add an attribute to the currently open tag.
document:close () Finish the document.
document:comment (text) Add a comment to the XML document.
document:endElement () Close an element tag.
document:startElement (name) Open a new element.
document:text (text) Add text to the document.
new (file, send, flush) Create a new XML document.


Functions

document:attribute (key, value)
Add an attribute to the currently open tag.

Parameters

  • key: The name of the attribute to add.
  • value: The value of the new attribute.
document:close ()
Finish the document. Finishes writing the document and calls the flush function, if available. Invoked automatically by garbage collection. Has no effect if the document has already been closed.
document:comment (text)
Add a comment to the XML document.

Parameters

  • text: The comment to add. Should not contain "--".
document:endElement ()
Close an element tag. Closes the most recent open element tag.
document:startElement (name)
Open a new element.

Parameters

  • name: The "tag name" of the element to open.
document:text (text)
Add text to the document.

Parameters

  • text: The string to add.
new (file, send, flush)
Create a new XML document. There are two ways to create an XML document. First, genx.new(file) creates a document that writes its contents to a file. Alternatively, genx.new(send[, flush]) creates a document that calls functions to output XML. The "send" function is mandatory while "flush" is optional.

Parameters

  • file: An open, writable file object.
  • send: A callback function invoked whenever new text is available. Should take a single string argument.
  • flush: A callback function invoked to flush any buffers and finish a document. Should take no parameters. Optional.

Return value:

A document object.