html 内嵌xml数据库,在SQLite数据库中存储XML/HTML文件 - 可能吗?
您可以將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)
總結
以上是生活随笔為你收集整理的html 内嵌xml数据库,在SQLite数据库中存储XML/HTML文件 - 可能吗?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HTML选择器属于jq的选择器吗,JQu
- 下一篇: html文字跳转备注,界面跳转备注.ht