Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > sql to xml

Reply
Thread Tools

sql to xml

 
 
Ros
Guest
Posts: n/a
 
      04-17-2007
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

 
Reply With Quote
 
 
 
 
Tim Golden
Guest
Posts: n/a
 
      04-17-2007
Ros wrote:
> 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.


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
 
Reply With Quote
 
 
 
 
Martin Drautzburg
Guest
Posts: n/a
 
      04-22-2007
Tim Golden wrote:

> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Reference, SQL Queries, SQL help ecoolone ASP .Net 0 01-03-2008 10:58 AM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
ANN: New XML Videos Demonstrating Data Integration and Web Publishing using SQL/XML, XSLT, and Stylus Studio Stylus Studio XML 0 07-26-2004 09:15 PM
Tools to extract data from SQL database and convert it into XML & insert XML data into SQL databases Harry Zoroc XML 1 07-12-2004 10:10 PM
simple(?) xml/xsl problem with xml from sql query dSchwartz XML 1 03-06-2004 02:06 AM



Advertisments