How to get the ElementTree.toString method to output a non breaking space (nbsp)?

651 Views Asked by At

How can I get the ElementTree.toString method to output   from a node's text attribute?

import xml.etree.cElementTree as ET

node = ET.Element("node")
node.text = "hello there"
print(ET.tostring(node, encoding = 'utf8', method = "xml", xml_declaration = False).decode('utf8'))

outputs:

<node>hello&amp;nbsp;there</node>

But I would like it to recognise the &nbsp; entity and output:

<node>hello&nbsp;there</node>
0

There are 0 best solutions below