#!/usr/local/bin/python2 import xml.etree.ElementTree as etree class C(etree.TreeBuilder): def start(self, tag, attrs): print super(C, self).start(tag, attrs) def data(self, data): print super(C, self).data(data) def end(self, tag): print super(C, self).end(tag) def close(self): return super(C, self).close() p = etree.XMLParser(target=C()) p.feed('b') print p.close().text