xml.dom.minidom - bug ? future ?

Roman Yakovenko romany at actimize.com
Thu Sep 4 13:41:06 CEST 2003


	Hi. What I don't understand is why I dump to xml string that contains
new - lines and when I read it from xml new lines replaced by spaces. 
May be I do something wrong? Or may be I just need to define encoding?
Here is some simple program that reproduce it.


#------------------
import xml.dom.minidom 

doc = """1
2
3
4
5
6
7
8"""

def save():
    DOMImpl = xml.dom.minidom.getDOMImplementation()
    controller_doc = DOMImpl.createDocument( None, "Multiline", None)   
    controller_elem = controller_doc.documentElement
    controller_elem.setAttribute( "str", doc )
    controller_xml = controller_elem.toxml()
    session = file( "c:/temp/__stam222.xml", 'w+' )
    session.write( controller_xml )
    session.close()

def load():
    controller_doc = xml.dom.minidom.parse( "c:/temp/__stam222.xml" )
    controller_elem = controller_doc.documentElement
    ldoc = controller_elem.getAttribute( "str" )
    print ldoc
    return ldoc
    
save()

assert doc == load()

#------------------

Thanks
	
	Roman





More information about the Python-list mailing list