skip to navigation
skip to content

streamingxmlwriter 1.0.0

A lightweight pythonic standard compliant streaming xml writer

streamingxmlwriter

A lightweight pythonic standard compliant streaming xml writer.

from io import BytesIO

import streamingxmlwriter

stream = BytesIO()
with streamingxmlwriter.from_stream(stream) as writer:
    writer.start_namespace('myns', 'http://mynamespace.org/')
    with writer.element('myns:root', {'att1': '1'}):
        with writer.element('myns:child1'):
            writer.characters('text content')
        writer.comment(' a comment ')
        with writer.element('myns:child2'):
            writer.characters('text content')
        # shortcut for elements containing a single text node
        writer.text_element('myns:child3', 'text content', {'att2': '2'})

For more API examples, look at the documentation of the StreamingXMLWriter class in core.py.

Under the hood it generates SAX events to the standard xml.sax.saxutils.XMLGenerator. It also provides a from_sax_handler constructor so it can also be used to emit sax events for other purposes than outputing to an io stream.

Python 2 (2.7+) and python 3 (3.3+) are supported.

Supported XML features are:

  • elements
  • attributes
  • text
  • processing instructions
  • comments
  • selectable encoding
  • namespaces for elements and attributes, with or without prefix

Unsupported XML features (yet):

  • DOCTYPE declaration
  • entities
  • CDATA sections

Credits

Author

  • Stéphane Bidoul (ACSONE)

Maintainer

This module is maintained by ACSONE SA/NV.

 
File Type Py Version Uploaded on Size
streamingxmlwriter-1.0.0-py2.py3-none-any.whl (md5) Python Wheel py2.py3 2016-02-17 4KB
streamingxmlwriter-1.0.0.tar.gz (md5) Source 2016-02-17 6KB