python - Preventing minidom from escaping already escaped text -


import xml.dom.minidom  text='2 > 1'  impl = xml.dom.minidom.getdomimplementation() doc = impl.createdocument(none, "foobar", none) docelem = doc.documentelement text = doc.createtextnode(text) docelem.appendchild(text)  f=open('foo.xml', 'w') doc.writexml(f) f.close() 

i expected foo.xml read follows:

<?xml version="1.0" ?><foobar>2 &gt; 1</foobar> 

but in fact reads:

<?xml version="1.0" ?><foobar>2 &amp;gt; 1</foobar> 

how can stop minidom escaping escaped sequence? in application text being read (non-xml) document, cannot write text = '2 > 1'.

unescape before inserting:

from xml.sax.saxutils import unescape  text = doc.createtextnode(unescape(text)) 

the escaping takes place when writing , cannot disabled, nor should be. want include literal &gt; text in xml, , should escaped if do. if input xml escaped, unescape before inserting.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -