[XML-SIG] xml.dom.minidom unwanted escaping
Kai Hendry
k75930@ky.hkkk.fi
Tue, 27 May 2003 16:44:35 +0300
This is a MIME-formatted message. If you see this text it means that your
E-mail software does not support MIME-formatted messages.
--=_courier-11959-1054043106-0001-2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
I have a little code sample attached.
I do not want:
$ ./domtest.py
<?xml version="1.0" ?>
<test>
<keywords>
foo & bar
</keywords>
<title>
"work"
</title>
</test>
I want:
$ ./domtest.py
<?xml version="1.0" ?>
<test>
<keywords>
foo & bar
</keywords>
<title>
"work"
</title>
</test>
Any ideas folks?
The joys of XML. :)
Kind regards,
-Kai Hendry
--=_courier-11959-1054043106-0001-2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="domtest.py"
#!/usr/bin/env python2
import re
import xml.dom.minidom
import os
import string
def create(dict, file_object):
newdoc = xml.dom.minidom.Document()
testdoc = newdoc.createElement("test")
newdoc.appendChild(testdoc)
for key, value in dict.items():
key = newdoc.createElement("%s" % string.lower(key))
key.appendChild(newdoc.createTextNode(value))
testdoc.appendChild(key)
newdoc.writexml(file_object)
return newdoc.toprettyxml()
if __name__ == "__main__":
dict = {'title': '"work"', 'keywords': 'foo & bar'}
os.umask(022)
file = open('/tmp/test.xml', 'w')
print create(dict, file)
file.flush()
file.close()
--=_courier-11959-1054043106-0001-2--