To elaborate: ######################################################## from xml.dom.pulldom import START_ELEMENT, parse import io
sampleData = u"""<?xml version="1.0"?> <data> <country name="Liechtenstein"> <rank updated="yes">2</rank> <year>2008</year> <gdppc>141100</gdppc> <neighbor name="Austria" direction="E"/> <neighbor name="Switzerland" direction="W"/> </country> <country name="Singapore"> <rank updated="yes">5</rank> <year>2011</year> <gdppc>59900</gdppc> <neighbor name="Malaysia" direction="N"/> </country> <country name="Panama"> <rank updated="yes">69</rank> <year>2011</year> <gdppc>13600</gdppc> <neighbor name="Costa Rica" direction="W"/> <neighbor name="Colombia" direction="E"/> </country> </data> """ doc = parse(io.StringIO(sampleData)) for event, node in doc: if event == START_ELEMENT and node.localName == "country": doc.expandNode(node) print("--------------") print("This is the node for " + node.getAttribute('name')) print("--------------") print(node.toxml()) print("\n\n") ######################################################## We can decide and make control-flow decisions in a stream-like manner. Note that we can even look at attributes, before printing the node back wherever we want. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor