stripping fields from xml file into a csv

Zaphod zaphod at beeblebrox.net
Sat Feb 27 20:52:15 EST 2010


On Sat, 27 Feb 2010 12:50:38 -0800, Hal Styli wrote:

> Hello,
> 
> Can someone please help.
> I have a sed solution to the problems below but would like to rewrite in
> python...
> 
> I need to strip out some data from a quirky xml file into a csv:
> 
> from something like this
> 
> < ..... cust="dick" .... product="eggs" ... quantity="12" .... > < ....
> cust="tom" .... product="milk" ... quantity="2" ...> < .... cust="harry"
> .... product="bread" ... quantity="1" ...> < .... cust="tom" ....
> product="eggs" ... quantity="6" ...> < ..... cust="dick" ....
> product="eggs" ... quantity="6" .... >
> 
> to this
> 
> dick,eggs,12
> tom,milk,2
> harry,bread,1
> tom,eggs,6
> dick,eggs,6
> 
> I am new to python and xml and it would be great to see some slick ways
> of achieving the above by using python's XML capabilities to parse the
> original file or python's regex to achive what I did using sed.
> 
> Thanks for any constructive help given.
> 
> Hal

Start here:

http://pyxml.sourceforge.net/topics/



More information about the Python-list mailing list