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 > 1</foobar>
but in fact reads:
<?xml version="1.0" ?><foobar>2 &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 >
text in xml, , should escaped if do. if input xml escaped, unescape before inserting.
Comments
Post a Comment