genshi.input.XMLParser

Package genshi :: Module input :: Class XMLParser |

# Class XMLParser

    object --+
             |
            XMLParser

Generator-based XML parser based on roughly equivalent code in Kid/ElementTree.

The parsing is initiated by iterating over the parser object:

    >>> parser = XMLParser(StringIO('<root id="2"><child>Foo</child></root>'))
    >>> for kind, data, pos in parser:
    ...     print kind, data
    START (QName(u'root'), Attrs([(QName(u'id'), u'2')]))
    START (QName(u'child'), Attrs())
    TEXT Foo
    END child
    END root

Instance Methods
__init__(self, source, filename=None, encoding=None) Initialize the parser for the given XML input. |
parse(self) Generator that parses the XML source, yielding markup events. |
__iter__(self) |
Inherited from `object`: `__delattr__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__str__`

Class Variables
| name = ``'``oacute``'``
| value = `243`

Properties
Inherited from `object`: `__class__`

Method Details

### __init__(self, source, filename=None, encoding=None) (Constructor) |
Initialize the parser for the given XML input. Parameters: `source` - the XML text as a file-like object `filename` - the name of the file, if appropriate `encoding` - the encoding of the file; if not specified, the encoding is assumed to be ASCII, UTF-8, or UTF-16, or whatever the encoding specified in the XML declaration (if any) Overrides: object.__init__

### parse(self) |
Generator that parses the XML source, yielding markup events. Returns: a markup event stream Raises: `ParseError` - if the XML text is not well formed