Edgewall Software

ApiDocs/0.3.x/genshi.output

Version 1 (modified by cmlenz, 8 years ago)

API documentation for 0.3.x branch

genshi.output

This module provides different kinds of serialization methods for XML event streams.

DocType

Defines a number of commonly used DOCTYPE declarations as constants.

XMLSerializer

Produces XML text from an event stream.

>>> from genshi.builder import tag
>>> elem = tag.div(tag.a(href='foo'), tag.br, tag.hr(noshade=True))
>>> print ''.join(XMLSerializer()(elem.generate()))
<div><a href="foo"/><br/><hr noshade="True"/></div>

XHTMLSerializer

Produces XHTML text from an event stream.

>>> from genshi.builder import tag
>>> elem = tag.div(tag.a(href='foo'), tag.br, tag.hr(noshade=True))
>>> print ''.join(XHTMLSerializer()(elem.generate()))
<div><a href="foo"></a><br /><hr noshade="noshade" /></div>

HTMLSerializer

Produces HTML text from an event stream.

>>> from genshi.builder import tag
>>> elem = tag.div(tag.a(href='foo'), tag.br, tag.hr(noshade=True))
>>> print ''.join(HTMLSerializer()(elem.generate()))
<div><a href="foo"></a><br><hr noshade></div>

TextSerializer

Produces plain text from an event stream.

Only text events are included in the output. Unlike the other serializer, special XML characters are not escaped:

>>> from genshi.builder import tag
>>> elem = tag.div(tag.a('<Hello!>', href='foo'), tag.br)
>>> print elem
<div><a href="foo">&lt;Hello!&gt;</a><br/></div>
>>> print ''.join(TextSerializer()(elem.generate()))
<Hello!>

If text events contain literal markup (instances of the Markup class), tags or entities are stripped from the output:

>>> elem = tag.div(Markup('<a href="foo">Hello!</a><br/>'))
>>> print elem
<div><a href="foo">Hello!</a><br/></div>
>>> print ''.join(TextSerializer()(elem.generate()))
Hello!

EmptyTagFilter

Combines START and STOP events into EMPTY events for elements that have no contents.

WhitespaceFilter

A filter that removes extraneous ignorable white space from the stream.


See ApiDocs/0.3.x, Documentation