# Rip, Mix and Burn Python

In his post on Dynamically Extending API's Mark provided the groundwork for some Python code I was working on at the same time. Mark ends up creating a list of tuples from an RSS file. What I needed was to run over an RSS file and produce a dictionary for each 'item' encountered. In addition I needed the namespace mapping to be "fixed". In this case "fixed" means that 'dc' always maps to the Dublin Core namespace. It is one of the flexibility/difficulty tradeoffs you make when you choose to use XML. That is, the chosen pre-fix for an element in a namespace need not be the same from document to document. For example the following two documents should be treated exactly the same:

<item xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:date>2003-01-12T00:18:05-05:00</bc:date>
<description>Upon waking, the dinosaur...</description>
</item>
<root:item xmlns:bc="http://purl.org/dc/elements/1.1/" xmlns:root="" >
<bc:date>2003-01-12T00:18:05-05:00</bc:date>
<description>Upon waking, the dinosaur...</description>
</root:item>


In either case the desired output should be a dictionary populated as such:

{ 'link': 'http://bitworking.org/news/8',
'dc:date': '2003-01-12T00:18:05-05:00',
'description': 'Upon waking, the dinosaur...',