On Mar 28, 12:40 pm, "fscked" <[EMAIL PROTECTED]> wrote: > I am a beginning pythoner and I am having a terrible time trying to > figure out how to do something that (it would seeme to me) should be > fairly simple. > > I have a CSV file of unknown encoding and I need to parse that file to > get the fields <--- DONE > I need to create an xml document that has the proper prolog and > namespace information in it. <--- NOT DONE > I need it to be encoded properly<--- Looks right in IE, not right in > any other app. > > I should say that I have googled my butt off, tried ElementTree, > CSV2XML, and various other things and cannot get any of them to work. > > A sample of the output I am looking for is as follows: > > <?xml version="1.0" encoding="UTF-8" standalone="yes"?> > <ns2:boxes xmlns:ns2="Boxes"> > <ns2:box id="9" mac="333333" d_a="2006" hw_ver="v1.1" sw_ver="3" > pl_h="No Data" name="Lounge" address="here" phone="555-5555" > country="US" city="LA"/> > <ns2:box id="7" mac="444444" d_a="2005" hw_ver="v1.0" sw_ver="3" > pl_h="No Data" name="MyHouse" address="there" phone="555-5556" > country="US" city="New York"/> > </ns2:boxes> > > Is there some fundamental thing I am not getting? I cannot get > 'tostrings' to work in ElementTree and I cannot figure the prolog out. > > I posted a similar message back in January, but haven't had much luck. > > PS > No I haven't been trying to do this since January, more important > things came up at work and I have just revived this. :)
I've never done this, but I found a recipe on the ActiveState website that looks like it would be helpful: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/159100 I think you could modify it to make it work. You could probably also use a combination of the csv module and the pyxml module (links below). http://pyxml.sourceforge.net/topics/ http://www.rexx.com/~dkuhlman/pyxmlfaq.html I also found a Python XML book: http://www.oreilly.com/catalog/pythonxml/chapter/ch01.html I hope that helps. I've started my own adventure into XML with XRC and wxPython. Mike -- http://mail.python.org/mailman/listinfo/python-list