xml.dom.minidom - bug ? future ?

  • Thread starter Roman Yakovenko
  • Start date
R

Roman Yakovenko

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
 
G

Guest

Roman said:
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?

You should not use new line characters in attribute values. According to
the XML specification, the XML processor must replace them with white
space, see

http://www.w3.org/TR/REC-xml#AVNormalize

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top