Howto create this XML string?

Fredrik Lundh fredrik at pythonware.com
Fri Jan 20 11:11:40 EST 2006


"Sbaush" wrote:

> in the elementtree implementation the tostring function doesn't work with a
> tree, work only with an element. What is the way to put the tree in a
> string?

this is the code you posted:

    root = ET.Element("manager")
    ... snip ...

    tree = ET.ElementTree(root)
    tree.write(sys.stdout)
    print

if you need the root variable instead of the tree variable, use root instead of tree.

or read the ET documentation; it explains how to get the root from a tree:

    http://effbot.org/zone/element-index.htm#usage
    http://effbot.org/zone/pythondoc-elementtree-ElementTree.htm

</F> 






More information about the Python-list mailing list