python and xml?

  • From: "Alex Hall" <mehgcap@xxxxxxxxx>
  • To: "Blind Programming List" <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 20 Jan 2010 10:39:48 -0500

Hi all,
Is there an easy way to parse xml files in python? Say you have the file

<products>
<item>
CD
<price>
$9.95
</price>
</item>
<item>
DVD
<price>
$14.95
</price>
</item>
</products>

I would like to be able to get as far into the structure as I want, then have everything below that be a list. For example:

items=xmlFile["products"]
print("item is "+items[0]+" and costs "+items[0]["price"])

I know I am mixing two types of data structures, but you see what I mean, at least I hope you do. Anyone have suggestions? I have not done a lot with xml before, but I understand children, nodes, and so on.


Have a great day,
Alex
Email: mehgcap@xxxxxxxxx
__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: