sql to xml

R

Ros

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
 
T

Tim Golden

Ros said:
Hi,
I am using xml data mapping list and would use it for validating data.

All right, I'm not going answer the question you're
asking (a) because I'm not really sure what the question
is and (b) because I'm not really an XML person.

I will make two other suggestions which may or
may not be of use:

1) Use MSSQL's builtin XML writing / reading capabilities.

2) Don't use XML if you don't need to.

You don't say why you're using XML but it really
isn't clear to me why you go to such extremes to
check the min and max length of data coming out
of a database.

Perhaps this is just sample code and your real
problem is more complex and must use XML, or
perhaps there really is some compelling reason
for using XML which escapes me here.

(I'm only even posting this drivel to show willing
since no-one's posted a response that I've seen).

TJG
 
M

Martin Drautzburg

Tim said:
2) Don't use XML if you don't need to.

I would call this advice a "golden rule" the violation of which has
caused serious pain in some of the projects I am working on.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top