469,336 Members | 5,552 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

xml.dom.minidom - bug ? future ?

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

Jul 18 '05 #1
1 2051
Roman Yakovenko wrote:
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

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by xtian | last post: by
3 posts views Thread by Sunil Movva | last post: by
5 posts views Thread by Skip Montanaro | last post: by
5 posts views Thread by Mike McGavin | last post: by
4 posts views Thread by webdev | last post: by
reply views Thread by Gary | last post: by
3 posts views Thread by aine_canby | last post: by
2 posts views Thread by ashmir.d | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.