Working in python, my goal is to parse through an XML doc I made and create a nested list of lists in order to access them later and parse the feeds. The XML doc resembles the following snippet:
<?xml version="1.0'>
<sources>
<!--Source List by Institution-->
<sourceList source="cbc">
<f>http://ift.tt/X70ZBf;
</sourceList>
<sourceList source="bbc">
<f>http://ift.tt/1mWR7iN;
<f>http://ift.tt/1mWR7iP;
</sourceList>
<sourceList source="reuters">
<f>http://ift.tt/X711sQ;
<f>http://ift.tt/1mWR7iT;
</sourceList>
</sources>
I would like to have something like nested lists where the inner most list would be the content between the <f></f> tags and the list above that one would be created with the names of the sources ex. source="reuters" would be reuters. Retrieving the info from the XML doc isn't a problem and I'm doing it with elementtree with loops retrieving with node.get('source') etc. The problem is I'm having trouble generating the lists with the desired names. I have tried appending but am unsure how to append to list with the names retrieved. Would a dictionary be better? What would be the best practice in this situation? And how might I make this work? If any more info is required just post a comment and I'll be sure to add it.
No comments:
Post a Comment