Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
您如何ElementTree在 Python 中获取字符串的来源?
ElementTree
import xml.etree.ElementTree as ET tree = ET.parse(source) root = tree.getroot() ET.tostring(root)
source请注意,和的内容之间可能存在格式差异ET.tostring(doc)。
source
ET.tostring(doc)
我知道不是,但我想知道为什么不是:
tree.tostring(root)
而不是当前的方式:
xml.etree.ElementTree.tostring(root)