sql to xml

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ros

    #1

    sql to xml

    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="Wr itten
    by"></ele>
    <ele id='A01' min_length="14" max_length="30" column_name="Pu blished
    by"></ele>
    <ele id='A01' min_length="15" max_length="30" column_name="Na me"></
    ele>
    <ele id='A01' min_length="11" max_length="25"
    column_name="Co pyrights"></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_deta ils"
    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(chi ld.attrib['id'])

    if child.tag == 'ele':
    w.push_ele(chil d.attrib['id'])

    # Here I am validating the data using "Map_list.x ml" 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

  • Tim Golden

    #2
    Re: sql to xml

    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

    Comment

    • Martin Drautzburg

      #3
      Re: sql to xml

      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.

      Comment

      Working...