#! /usr/bin/env python """A simple but useful XML dump routine. I have to read the DOM spec every time i try to write this from scratch, which hurts, so here it is once and for all. """ def _dump(elem, pad=""): print pad, elem.tagName for child in elem.childNodes: if (child.nodeType == child.ELEMENT_NODE): _dump(child, (pad + " ")) else: # todo: differentiate different kinds of non-element child print pad, child.nodeName, repr(child.nodeValue)