An XML generator:

  http://gflanagan.net/site/python/utils/xmlbuilder/

A single file: 'xmlbuilder.py'. The real work is done by the XmlWriter
class from the ElementTree package.  If you're on 2.5, then you'll need
to get the file 'SimpleXMLWriter.py' from

    http://effbot.org/zone/element-index.htm

and save it somewhere in your PYTHONPATH, eg. site-packages.  Then
change the import line in xmlbuilder.py :

change

    from elementtree.SimpleXMLWriter import XMLWriter

to

    from SimpleXMLWriter import XMLWriter

----------------------------------------------------------------------------

    >>> xml = XmlFragment()
    >>> root = xml.div()
    >>> print root
    <_XmlElement div>
    >>> print xml
    <div />
    >>> firstchild = root.p("Some text", id="1")
    >>> print xml
    <div><p id="1">Some text</p></div>
    >>> firstchild.br()
    <_XmlElement br>
    >>> print xml
    <div><p id="1">Some text<br /></p></div>
    >>> firstchild.add_text("more text, ")
    <_XmlText>
    >>> print xml
    <div><p id="1">Some text<br />more text, </p></div>
    >>> firstchild.add_text("and more.").br()
    <_XmlElement br>
    >>> print xml
    <div><p id="1">Some text<br />more text, and more.<br /></p></div>
    >>> root.add_comment("COMMENT")
    <_XmlComment>
    >>> print xml
    <div><p id="1">Some text<br />more text, and more.<br /></p><!--
COMMENT -->
    </div>

---------------------------------------------------------------------

-- 
http://mail.python.org/mailman/listinfo/python-announce-list

        Support the Python Software Foundation:
        http://www.python.org/psf/donations.html

Reply via email to