Newbie Python & XML

Jerry Sievers jerry at
Sat Jun 4 18:21:11 CEST 2005

"LenS" <lsumnler at> writes:

> I have a situation at work.  Will be receiving XML file which contains
> quote information for car insurance.  I need to translate this file
> into a flat comma delimited file which will be imported into a software
> package.  Each XML file I receive will contain information on one quote
> only.  I have documentation on layout of flat file and examples of XML
> file (lot of fields but only container tags and field tags no
> DTD's,look easy enough).  I am just starting to learn python and have
> never had to work with XML files before.  Working in MS Windows
> environment.  I have Python 2.4 with win32 extensions.
> 1. What else do I need

Well, if the XML file format is going to be fixed, there's no
difficulty here.

import the parseString from dom.minidom

Figure out how many levels of container the XMl doc has.  and descend
using the childNodes one or more times till you reach the data.

Data nodes are of nodeType == 3.  Iterate over them using nodeValue on
each.  Put them into a list and then paste you list together using
COMMAS or other delimiter.

This is the quick and dirty way!   Will barf totally if your upstream
data source throws you a curve.


> 2. Any examples of program doing the same.
> 3. Have read some stuff that indicates I may need ? schema of XML
> layout ????

Perhaps.  But probably not unless you are trying to build a highly
flexible parser.

> The rating company will ftp a quote realtime to a dir on my system.
> the python program will then have to poll the dir for new files and
> automaticly translate and initiate import.

A more elegant way of doing this is to pipe the FTP server log data
through a running process and if the file matches one that requires
this XML treatment, do it in real time.

May not be worth the trouble to implement in a low volume system

Jerry Sievers   305 854-3001 (home)     WWW ECommerce Consultant
                305 321-1144 (mobile

More information about the Python-list mailing list