xmltodict

Makes working with XML feel like you are working with JSON
Download

xmltodict Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • Martin Blech
  • Publisher web site:
  • http://code.google.com/u/martinblech/

xmltodict Tags


xmltodict Description

xmltodict is a Python module that makes working with XML feel like you are working with JSON, as in this "spec":Build Status>>> doc = xmltodict.parse("""... < mydocument has="an attribute" >... < and >... < many >elements< /many >... < many >more elements< /many >... < /and >... < plus a="complex" >... element as well... < /plus >... < /mydocument >... """)>>>>>> docu'an attribute'>>> doc>>> docu'complex'>>> docu'element as well'It's very fast (Expat-based) and has a streaming mode with a small memory footprint, suitable for big XML dumps like Discogs or Wikipedia:>>> def handle_artist(_, artist):... print artist>>> >>> xmltodict.parse(GzipFile('discogs_artists.xml.gz'),... item_depth=2, item_callback=handle_artist)A Perfect CircleFantômasKing CrimsonChris Potter...It can also be used from the command line to pipe objects to a script like this:import sys, marshalwhile True: _, article = marshal.load(sys.stdin) print article cat enwiki-pages-articles.xml.bz2 | bunzip2 | xmltodict.py 2 | myscript.pyAccessibleComputingAnarchismAfghanistanHistoryAfghanistanGeographyAfghanistanPeopleAfghanistanCommunicationsAutism...Or just cache the dicts so you don't have to parse that big XML file again. You do this only once: cat enwiki-pages-articles.xml.bz2 | bunzip2 | xmltodict.py 2 | gzip > enwiki.dicts.gzAnd you reuse the dicts with every script that needs them: cat enwiki.dicts.gz | gunzip | script1.py cat enwiki.dicts.gz | gunzip | script2.py...Ok, how do I get it?You just need to pip install xmltodictProduct's homepage


xmltodict Related Software