#NEWLINE# def xmliter_lxml( obj , nodename , namespace = None ) : #NEWLINE# #INDENT# from lxml import etree #NEWLINE# reader = _StreamReader ( obj ) #NEWLINE# tag = ( ( '{%s}%s' % ( namespace , nodename ) ) if namespace else nodename ) #NEWLINE# iterable = etree . iterparse ( reader , tag = tag , encoding = reader . encoding ) #NEWLINE# selxpath = ( '//' + ( ( 'x:%s' % nodename ) if namespace else nodename ) ) #NEWLINE# for ( _ , node ) in iterable : #NEWLINE# #INDENT# nodetext = etree . tostring ( node ) #NEWLINE# node . clear ( ) #NEWLINE# xs = Selector ( text = selxpath , type = 'xml' ) #NEWLINE# if namespace : #NEWLINE# #INDENT# xs . register_namespace ( 'x' , namespace ) #NEWLINE# #UNINDENT# ( yield xs . xpath ( selxpath ) [ 0 ] )