Search code examples
pythonxmlminidom

Python: Stopping miniDOM from expanding escape sequences


When xml.dom.minidom parses a piece of xml, it automagically converts escape characters for greater than and less than into their visual representation. For example:

>>> import xml.dom.minidom  
>>> s = "<example>4 &lt; 5</example>"
>>> x = xml.dom.minidom.parseString(s)
>>> x.firstChild.firstChild.data
u'4 < 5'

Does anyone know how to stop minidom from doing this?


Solution

  • >>> import xml.dom.minidom
    >>> s = "<example>4 &lt; 5</example>"
    >>> x = xml.dom.minidom.parseString(s)
    >>> x.firstChild.firstChild.toxml()
    u'4 &lt; 5'