Describes a module allowing programs in the Python programming language to generate large XML files without large amounts of processor memory; includes its implementation as a literate program.
Table of Contents
sox.py: The code prologue
Sox.start(): Start an element
Sox._nameCheck(): Is this a valid
Sox._unicodify(): Force to Unicode
Sox._checkCharRange(): Is this code point in a given set of intervals?
Sox._sortParams(): Classify content and attribute arguments
Sox._attrEscape(): Escape forbidden characters in attribute values
Sox._typeRouter(): Mapping of content parameter types to converter functions
Sox._buildAttrs(): Build XML attributes from a dictionary
Sox.leaf(): Write an element with no element children
Sox._startTag(): Write a start tag
Sox._emptyTag(): Write an empty XML tag
Sox._endTag(): Write an XML end tag
Sox.close(): Cleanup and close
Sox.pi(): Write a processing instruction
class Elt: One open element
soxtest: Test driver
This document describes a module for the Python programming language that helps in the generation of large XML documents without regard to processor memory limitations.
Sometimes, as when formatting a database query for Web
presentation as XHTML, or generating an XSL-FO file
destined for a PDF rendering, it is necessary to generate
quite large XML documents. The author's preferred
techniques for reading and writing XML from Python are
described in Python XML processing with
etbuilder module presented in that
document is especially handy for XML generation, allowing
generation of arbitrary XML structures with compact code.
However, these methods require that the entire XML document
reside as a tree in memory.
Hence, what the author needed was a module that generates XML sequentially, allowing the generation of quite large documents without significant memory requirements.