#!/usr/bin/env python # encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # """Creating XML documents """ #end_pymotw_header import sys from xml.etree.ElementTree import Element, SubElement, ElementTree top = Element('top') child = SubElement(top, 'child') child.text = 'This child contains text.' empty_child = SubElement(top, 'empty_child') for method in [ 'xml', 'html', 'text' ]: print method ElementTree(top).write(sys.stdout, method=method) print '\n'