Велосипед
def fetchall_xml(cur, pretty_print=True):
import lxml.etree
fields_value = cur.fetchall()
fields_name = tuple(i[0] for i in cur.description)
elements = lxml.etree.Element('elements')
for el in fields_value:
element = lxml.etree.SubElement(elements, 'element', attrib={'foo': 'bar'})
for j in range(len(fields_name)):
lxml.etree.SubElement(element, str(fields_name[j])).text = '{}'.format(el[j])
return lxml.etree.tounicode(elements, pretty_print=pretty_print)
def main():
conn = sqlite3.connect('compare.db')
cur = conn.cursor()
cur.execute('SELECT * FROM PRODUCT_EXCHANGERATE')
xml = fetchall_xml(cur)
print(xml)
main()