RE: python and xml?

  • From: "Ken Perry" <whistler@xxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 20 Jan 2010 20:41:25 -0500


You can do this several ways you might want to look at the mini dom it will
parse the xml into a parse tree and you can get the information that way.
That or you can use the sax style parser but that takes a bit more work.  It
depends on what type of machine your running on for example I write code for
small devices and if you use the dom or mini dom stuff it really is slow if
it's on a pc it is not slow it's pretty fast actually.  There is also Xpat
for python and there are all kinds of third party python xml parsers so it's
hard to say what you should use.

Ken

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Alex Hall
Sent: Wednesday, January 20, 2010 10:40 AM
To: Blind Programming List
Subject: python and xml?

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

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: