【发布时间】:2015-04-30 18:16:40
【问题描述】:
一些背景资料
我正在使用 SQLite 访问数据库并检索所需的信息。我在 Python 2.6 版中使用 ElementTree 来创建包含该信息的 XML 文件。
代码
这是我用来从数据库模式创建 XML 文件的代码。我已经用评论指出了错误发生的位置。
import sqlite3
import xml.etree.ElementTree as ET
db = sqlite3.connect("dataload.db")
root = ET.Element("databaseConfiguration")
software_attributes = ["id", "functionalDesignationHardware", "hwfin", "identname", "partnumber",
"repfin", "targetHardwareID"]
software = db.cursor().execute("SELECT %s from SOFTWARE_" % ", ".join([i + "_" for i in software_attributes]))
software_Data = software.fetchall()
for sw in software_Data:
sw_node = ET.SubElement(root, "Software")
for i in range(1, len(software_attributes)):
sw_node.set(software_attributes[i], str(sw[i]))
target_attributes = ["id", "functionalDesignationSoftware", "installscriptpathname", "ata", "status",
"swfin", "targetOSFC", "timestamp"]
tree = ET.ElementTree(root)
from xml.dom import minidom
print minidom.parseString(ET.tostring(root)).toprettyxml(indent = " ")
## The error pops up at this line (when trying to generate the XML) ##
tree.write("New_Database.xml)
问题
如何解决此错误?我还看到了其他一些必须添加或编辑引号的问题 - 我是否需要做类似的事情,以及如何做?
【问题讨论】:
-
乍一看,除了文件名上缺少右引号外,它看起来还不错。错误信息是什么意思?
标签: xml sqlite python-2.6 elementtree eol