genshi.input

Package genshi :: Module input |

# Module input

Support for constructing markup streams from files, strings, or other sources.

Classes
| ParseError Exception raised when fatal syntax errors are found in the input being parsed.
| XMLParser Generator-based XML parser based on roughly equivalent code in Kid/ElementTree.
| HTMLParser Parser for HTML input based on the Python HTMLParser module.

Functions
ET(element) Convert a given ElementTree element to a markup stream. |
XML(text) Parse the given XML source and return a markup stream. |
HTML(text, encoding=`'``utf-8``'`) Parse the given HTML source and return a markup stream. |

Function Details

### ET(element) |
Convert a given ElementTree element to a markup stream. Parameters: `element` - an ElementTree element Returns: a markup stream

### XML(text) |
Parse the given XML source and return a markup stream. Unlike with XMLParser, the returned stream is reusable, meaning it can be iterated over multiple times:
    >>> xml = XML('<doc><elem>Foo</elem><elem>Bar</elem></doc>')
    >>> print xml
    <doc><elem>Foo</elem><elem>Bar</elem></doc>
    >>> print xml.select('elem')
    <elem>Foo</elem><elem>Bar</elem>
    >>> print xml.select('elem/text()')
    FooBar
Parameters: `text` - the XML source Returns: the parsed XML event stream Raises: `ParseError` - if the XML text is not well-formed

### HTML(text, encoding=`'``utf-8``'`) |
Parse the given HTML source and return a markup stream. Unlike with HTMLParser, the returned stream is reusable, meaning it can be iterated over multiple times:
    >>> html = HTML('<body><h1>Foo</h1></body>')
    >>> print html
    <body><h1>Foo</h1></body>
    >>> print html.select('h1')
    <h1>Foo</h1>
    >>> print html.select('h1/text()')
    Foo
Parameters: `text` - the HTML source Returns: the parsed XML event stream Raises: `ParseError` - if the HTML text is not well-formed, and error recovery fails