how to write an xml file without dom.ext?

Nitin Pawar nitinpawar432 at gmail.com
Thu Oct 7 06:59:35 EDT 2010


import xml.dom.minidom
import os
xml = xml.dom.minidom.parse(xml_fname) # or
xml.dom.minidom.parseString(xml_string)
pretty_xml_as_string = xml.toprettyxml()
file = open("newfile", 'w')
file.write(pretty_xml_as_string)
file.close()


   1.





On Thu, Oct 7, 2010 at 4:16 PM, hackingKK <hackingkk at gmail.com> wrote:

>  On Thursday 07 October 2010 03:49 PM, Nitin Pawar wrote:
>
> why not just convert it to string with print pretty and then normal write
> to a file
>
>
>  Can you give an example.
>
> happy hacking.
> Krishnakant.
>
>  On Thu, Oct 7, 2010 at 3:36 PM, hackingKK <hackingkk at gmail.com> wrote:
>
>> Hello all.
>> I need to create an xml file.
>> I am using dom.minidom module.
>> It works fine as long as the xml tree is created.
>> But I get the import error for dom.ext.
>> I searched through the python docs but can't find a solution.
>> I am pritty sure that there is way to write the file to disk without using
>> the ext module.
>> Since there are so many software doing this with python 2.6 I am sure it
>> works.
>> So can some one tell me if there is a way to avoide ext and prittyprint
>> and still write a file to the disk?
>>
>> Happy hacking.
>> Krishnakant.
>>
>>
>>
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
>
> --
> Nitin Pawar
>
>
>


-- 
Nitin Pawar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101007/2aeb3fa9/attachment-0001.html>


More information about the Python-list mailing list