<s> from xml . parsers import expat <EOL> class XmlParser ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , s ) : <EOL> self . currentData = '<STR_LIT>' <EOL> self . currentName = None <EOL> self . currentAttrs = None <EOL> self . elementStack = [ ] <EOL> self . currentKey = None <EOL> self . lastKey = <NUM_LIT:0> <EOL> self . p = expat . ParserCreate ( ) <EOL> self . p . StartElementHandler = self . StartElementHandler <EOL> self . p . EndElementHandler = self . EndElementHandler <EOL> self . p . CharacterDataHandler = self . CharacterDataHandler <EOL> def parse ( self , s ) : <EOL> self . p . Parse ( s ) <EOL> def newElement ( self , parentElement , thisElement , thisName , thisAttrs ) : <EOL> pass <EOL> def finishElement ( self , parentElement , thisElement , thisName , thisAttrs , <EOL> thisData ) : <EOL> pass <EOL> def CharacterDataHandler ( self , data ) : <EOL> self . currentData += data <EOL> def EndElementHandler ( self , name ) : <EOL> assert ( self . currentName == name ) <EOL> self . finishElement ( self . elementStack [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] , self . currentKey , <EOL> self . currentName , self . currentAttrs , <EOL> self . currentData ) <EOL> ( self . currentKey , self . currentName , self . currentAttrs , <EOL> self . currentData ) = self . elementStack . pop ( ) <EOL> def StartElementHandler ( self , name , attrs ) : <EOL> self . elementStack . append ( ( self . currentKey , self . currentName , <EOL> self . currentAttrs , self . currentData ) ) <EOL> self . currentName = name <EOL> self . currentAttrs = attrs <EOL> self . currentData = '<STR_LIT>' <EOL> self . newElement ( self . currentKey , self . lastKey , name , attrs ) <EOL> self . currentKey = self . lastKey <EOL> self . lastKey += <NUM_LIT:1> </s>
