event, root = next(context)
for event, elem in context:
    if event == 'end':
        if elem.tag == 'bucket':
            elem.tail = None
print(cElementTree.tostring(elem))
if elem.tag == 'resFrame':
    if elem.find('id').text == ':4:39644:482:-1:1':
        elem.tail = None
print(cElementTree.tostring(elem))
if elem.tag in ['bucket', 'frame', 'resFrame']:
    root.clear()
print('</snapDoc>')
main()
Splitting a large XML file in Python