DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Efficiently Process Big Xml Files With CElementTree

04.10.2012
| 6177 views |
  • submit to reddit
        ElementTree is becoming python's standard XML framework.
It also supports processing data as it coming/loading.
import cElementTree

for event, elem in cElementTree.iterparse(file):
    if elem.tag == "record":
        ... process record element ...
        elem.clear()