您可以将XML/HTML文件作为文本在文本列中毫无问题地存储。
一个明显的缺点是,您无法真正查询XML中的值。
编辑: 下面是一个例子。只需将您的XML文件读入一个变量并将其存储在数据库中,就像您将存储任何字符串以及要存储的任何其他值一样。当你想使用XML时,只需从数据库中读取它并用XML解析器解析它即可。
# connect to database and create table
import sqlite3
conn = sqlite3.connect(":memory:")
conn.execute('''create table my_table (value1 integer, value2 integer, xml text)''')
# read text from file
f = file('/tmp/my_file.xml')
xml_string_from_file = f.read()
# insert text into database
cur = conn.cursor()
cur.execute('''insert into my_table (value1, value2, xml) values (?, ?, ?)''', (23, 42, xml_string_from_file))
cur.commit()
# read from database into variable
cur.execute('''select * from my_table''')
xml_string_from_db = cur.fetchone()[2]
# parse with the XML parser of your choice
from xml.dom.minidom import parseString
dom = parseString(xml_string_from_db)