【发布时间】:2017-01-08 19:15:28
【问题描述】:
我目前正在使用 ElementTree 编写一个 XML 文件
for i in range(len(lang_list)):
body = ET.SubElement(root, "body")
body.set("lang", lang_list[i])
# body.text = text_list[i] + " " + common_text
body.text =unescape(escape('<![CDATA[')) + text_list[i] + " " + common_text + unescape(escape(']]>'))
body.tail = "\n\t"
outpath = os.getcwd()
file = outpath + "\\test.xml"
tree.write(file, xml_declaration=True)
但是有一个XML声明,比如
DOCTYPE email-template PUBLIC "-//yourcompany, Inc.//DTD email-template//EN" "email-template.dtd">
如何将这些信息写入 XML 文件?
【问题讨论】:
-
我在这里写了一个答案,但问题在我提交之前就关闭了。你可以看到我的回答here。