import xmllib, sys class AddresslistParser(xmllib.XMLParser): def __init__(self, data = {}): xmllib.XMLParser.__init__(self) self.data = {} def syntax_error(self, msg): sys.stderr.write(msg) def start_addressbook(self, attr): for key in attr.keys(): self.data[key] = attr[key] def start_context(self, attr): print 'context', attr def start_item(self, attr): print 'item', attr def start_name(self, attr): print 'name', attr def start_address(self, attr): print 'address', attr if __name__ == '__main__': import sys p = AddresslistParser() p.feed(open(sys.argv[1]).read())