sql to xml

Discussion in 'Python' started by Ros, Apr 17, 2007.

  1. Ros

    Ros Guest

    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
    Ros, Apr 17, 2007
    #1
    1. Advertising

  2. Ros

    Tim Golden Guest

    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
    Tim Golden, Apr 17, 2007
    #2
    1. Advertising

  3. 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.
    Martin Drautzburg, Apr 22, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dSchwartz
    Replies:
    1
    Views:
    353
    Bryant Likes
    Mar 6, 2004
  2. Harry Zoroc
    Replies:
    1
    Views:
    928
    Gregory Vaughan
    Jul 12, 2004
  3. Stylus Studio
    Replies:
    0
    Views:
    410
    Stylus Studio
    Jul 26, 2004
  4. ecoolone
    Replies:
    0
    Views:
    752
    ecoolone
    Jan 3, 2008
  5. Erik Wasser
    Replies:
    5
    Views:
    445
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page