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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值