"""Test of the saxutils.XMLGenerator class.

$Id$
"""

import StringIO
from test import test_support
from xmlcore.sax.saxutils import XMLGenerator

def test_basic ():
    """
    >>> gen = XMLGenerator()
    >>> gen.startDocument()
    <?xml version="1.0" encoding="iso-8859-1"?>
    >>> gen.startElement('root', dict(attr1='value1', attr2 = '<, >, and &'))
    <root attr2="&lt;, &gt;, and &amp;" attr1="value1">
    >>> gen.characters('Paragraph containing <, >, and &')
    Paragraph containing &lt;, &gt;, and &amp;
    >>> gen.ignorableWhitespace('\\n\\n')
    <BLANKLINE>
    <BLANKLINE>
    >>> gen.processingInstruction('xml-stylesheet', 'http://example.com/css')
    <?xml-stylesheet http://example.com/css?>
    >>> gen.endElement('root')
    </root>
    """

def test_ns ():
    """
    >>> gen = XMLGenerator()
    >>> ns_uri = 'http://example.com/xbel'
    >>> gen.startDocument()
    <?xml version="1.0" encoding="iso-8859-1"?>
    >>> gen.startPrefixMapping('xbel', ns_uri)
    >>> gen.startElementNS((ns_uri, 'xbel'), 'xbel:xbel',
    ...                    {(ns_uri, 'version'):'1.0'})
    <xbel:xbel xmlns:xbel="http://example.com/xbel" xbel:version="1.0">
    >>> gen.startElementNS((ns_uri, 'title'), 'xbel:title', {})
    <xbel:title>
    >>> gen.endElementNS((ns_uri, 'title'), 'xbel:title')
    </xbel:title>
    >>> gen.startElementNS((None, 'about'), 'about', {})
    <about>
    >>> gen.endElementNS((None, 'about'), 'about')
    </about>
    >>> gen.endElementNS((ns_uri, 'xbel'), 'xbel:xbel')
    </xbel:xbel>
    >>> gen.endPrefixMapping('xbel')
    """
    
def main():
    from test import test_saxgen
    test_support.run_doctest(test_saxgen, verbosity=True)


if __name__ == '__main__':
    main()
