0

如何让 ElementTree.toString 方法 从节点的文本属性输出?

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'))

输出:

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

但我希望它能够识别&nbsp;实体和输出:

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

0 回答 0