"""Yet another XML parser This is meant to be very simple: - stack based - The parser has a table of start handlers and end handlers. - start tag handlers are called with the parser instance, tag names and attributes. The result is placed on the stack. The default handler places a special object on the stack (uh, a list, with the tag name and attributes as the first two elements. ;) - end tag handlers are called with the object on the parser, the tag name, and top of the stack right after it has been removed. The result is appended to the object on the top of the stack. Note that namespace attributes should recieve some special handling. Oh well. """ import string import xmllib from pickle import * from types import ListType class xyap: start_handlers={} end_handlers={} def __init__(self): top=[] self._stack=_stack=[top] self.push=_stack.append self.append=top.append def handle_data(self, data): self.append(data) def unknown_starttag(self, tag, attrs): if type(attrs) is ListType: x=0 temp={} while x examples.getStateName 41 lowerBound 18 upperBound 139 12 Egypt 0 -31 """ data=string.split(data,'\n') r=[] for C in XYap, xmlrpc: p=C() for l in data: p.feed(l) p.close() r.append(p._stack) return r if __name__=='__main__': print test()