获取Python xml ElementTree的字符串源代码

Jam*_*mes 9 python xml elementtree

你如何ElementTree在Python中获得字符串的来源?

unu*_*tbu 8

import xml.etree.ElementTree as ET
tree = ET.parse(source)
root = tree.getroot()
ET.tostring(root)
Run Code Online (Sandbox Code Playgroud)

请注意,source和的内容之间可能存在格式差异ET.tostring(doc).