sorry forgot to mention that tried with specifying the encoding in toxml() too but with same results.
>>> e.toxml("UTF-8") '<abc>&lt;hello&gt;bhaskar&lt;/hello&gt;</abc>' >>> e.toxml("utf-8") '<abc>&lt;hello&gt;bhaskar&lt;/hello&gt;</abc>' Thanks. Bhaskar. On Mon, Oct 26, 2009 at 11:27 AM, bhaskar jain <bhaskar.jain2...@gmail.com>wrote: > Hello, > > I am stuck while escaping "<" and ">" in the xml file using > xml.dom.minidom. > I tried to get the unicode hex value and use that instead ( > http://slayeroffice.com/tools/unicode_lookup/) > Tried to use the standard "<" and ">" but still with no success. > I saw similar bugs in python bugzilla - http://bugs.python.org/issue5752and > some others but not sure. > > > >>> from xml.dom.minidom import Document > >>> doc = Document() > >>> e = doc.createElement("abc") > >>> s1 = '<hello>bhaskar</hello>' > >>> text = doc.createTextNode(s1) > >>> e.appendChild(text) > <DOM Text node "<hello>bha..."> > > >>> e.toxml() > '<abc><hello>bhaskar</hello></abc>' > > same result with writexml() > > > >>> from xml.dom.minidom import Document > >>> doc = Document() > >>> e = doc.createElement("abc") > >>> s1 = u'<hello>bhaskar</hello>' > >>> text = doc.createTextNode(s1) > >>> e.appendChild(text) > <DOM Text node "<hello&..."> > > >>> e.toxml() > u'<abc>&lt;hello&gt;bhaskar&lt;/hello&gt;</abc>' > > > Tried other ways but with same results. > Only way is to override the writer and replace like shown here - > http://www.velocityreviews.com/forums/t330646-a-simple-xmldomminidom-question.html > . > > Has anybody solved this? > > I want to have a text node with contents as > "ds:X509Certificate>-----BEGIN CERTIFICATE----- </ds:X509Certificate>". > Creating an element as "ds:x509Certificate" and then creating a text node > with the certificate and appending it to the element works but a third > party-library fails to parse it. > So would like to have a single text node with the contents. > > Thanks. > > --Bhaskar. > > > _______________________________________________ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers