Hi,
I wish to write xml file after validating data from mssql database. I am using xml data mapping list and would use it for validating data.
Here is the program :
Map_list.xml :
<loop id=Book1'>
<ele id='A01' min_length="10" max_length="25" column_name="Written by"></ele> <ele id='A01' min_length="14" max_length="30" column_name="Published by"></ele> <ele id='A01' min_length="15" max_length="30" column_name="Name"></ ele> <ele id='A01' min_length="11" max_length="25" column_name="Copyrights"></ele> </loop>
Program :
from cElementTree import iterparse
import pymssql
# Database connection details
host = '192.168.1.1'
db = 'Books'
usr = 'ros_albert'
pwd = 'ros_albert'
conn = pymssql.connect(host=host, user=usr, password=pwd, database=db) table = "books_details" cursor = conn.cursor
cursor.execute( 'select * from books_details')
for row in cursor.fetchall:
fname = row[0]
# Here is the code to validate the minimum length & maximum length of data, if its ok then I would write the data into xml file
context = iterparse('Map_list.xml', events=("start", "end")) root = None for event, child in context:
if event == "start":
if child.tag == 'loop':
w.push_loop(child.attrib['id'])
if child.tag == 'ele':
w.push_ele(child.attrib['id'])
# Here I am validating the data using "Map_list.xml" file, validation part is working fine.
if event == "end":
if child.tag == 'ele':
writer.pop_ele
if child.tag == 'loop':
writer.pop_loop
I am able to write a data from 1 xml file to another but not getting how to write & validate data from sql to xml. May be I am not sure what mapping is. I wish to map the data columns in sql database with the xml data.
any help would be highly appreciated.
Regards,
Ros
I wish to write xml file after validating data from mssql database. I am using xml data mapping list and would use it for validating data.
Here is the program :
Map_list.xml :
<loop id=Book1'>
<ele id='A01' min_length="10" max_length="25" column_name="Written by"></ele> <ele id='A01' min_length="14" max_length="30" column_name="Published by"></ele> <ele id='A01' min_length="15" max_length="30" column_name="Name"></ ele> <ele id='A01' min_length="11" max_length="25" column_name="Copyrights"></ele> </loop>
Program :
from cElementTree import iterparse
import pymssql
# Database connection details
host = '192.168.1.1'
db = 'Books'
usr = 'ros_albert'
pwd = 'ros_albert'
conn = pymssql.connect(host=host, user=usr, password=pwd, database=db) table = "books_details" cursor = conn.cursor
cursor.execute( 'select * from books_details')
for row in cursor.fetchall:
fname = row[0]
# Here is the code to validate the minimum length & maximum length of data, if its ok then I would write the data into xml file
context = iterparse('Map_list.xml', events=("start", "end")) root = None for event, child in context:
if event == "start":
if child.tag == 'loop':
w.push_loop(child.attrib['id'])
if child.tag == 'ele':
w.push_ele(child.attrib['id'])
# Here I am validating the data using "Map_list.xml" file, validation part is working fine.
if event == "end":
if child.tag == 'ele':
writer.pop_ele
if child.tag == 'loop':
writer.pop_loop
I am able to write a data from 1 xml file to another but not getting how to write & validate data from sql to xml. May be I am not sure what mapping is. I wish to map the data columns in sql database with the xml data.
any help would be highly appreciated.
Regards,
Ros