import pyodbc
import xlrd
import xml.etree.ElementTree as ET
print("Connecting..")
conn = pyodbc.connect('Driver={SQL Server};'
'Server=TEST;'
'Database=test;'
'Trusted_Connection=yes;')
print("DB Connected..")
XMLFilePath = open('C:HelloWorld.xml')
x = etree.parse(XBRLFilePath)
with open("FileName", "wb") as f:
f.write(etree.tostring(x))
CreateTable = """
create table test.dbo.TEMP
(
XBRLFile XML
)
"""
cursor = conn.cursor()
try:
cursor.execute(CreateTable)
conn.commit()
except pyodbc.ProgrammingError:
pass
print("Table Created..")
InsertQuery = """
INSERT INTO test.dbo.TEMP (
XBRLFile
) VALUES (?)"""
values = etree.tostring(x)
cursor.execute(InsertQuery, values)
conn.commit()
conn.close()