0

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>
Sam
  • 616
  • 7
  • 19
  • Similar to https://stackoverflow.com/q/7986272/407651 – mzjn Mar 29 '21 at 18:05
  • Note that `hello there` on its own is not a well-formed XML document since it contains no definition of the `nbsp` entity. – mzjn Mar 30 '21 at 06:12

0 Answers0