How to replace a node in XML using Python with value fetched from database using minidom?
===

I am very new to Python and got stuck to a point. I am trying to replace selective nodes in an XML document with corresponding values from MS SQL Server. I am supposed to use only minidom to achieve the same. The database table consists buyer information in Polish which is unicoded and i am supposed to replace the English information in existing XML with Polish data.
Following is the structure of XML document where changes are supposed to happen:


    <INVPARTNER>
                <INVOICE_BUYER>XXXXX</INVOICE_BUYER>          (Unique Customer ID)
                <INVOICE_PAYERNO>92254</INVOICE_PAYERNO>     
                <INVOICE_BUYERVATID>BLAH</INVOICE_BUYERVATID>
                <buyer1>ABC</buyer1>                     (Customer name 1: DB Value CUSTNAME1)
                <buyer2/>                                (Customer name 2: DB Value CUSTNAME2)
                <buyer3>XYZ</buyer3>                     (Customer name 3: DB Value CUSTADDR1)
                <buyer4/>                                (Customer name 4: DB Value CUSTADDR2)
                <buyer5>PQR</buyer5>
                <buyer6>ITALY</buyer6>
                <buyer7/>
                <buyer8></buyer8>
                <buyer9/>
                <buyer10/>


I have written following code to achieve the same but failing to do so:


    import pyodbc
    from xml.dom.minidom import parse
    import os
    docTypes = {'INVOICE':['INVOICE_BUYER', 'INVOICE_CONSIGNEE']}
    changeValues = {'INVOICE':{"buyer1":'CUSTNAME1', "buyer2":'CUSTNAME2', "buyer3":'CUSTADDRESS1', "buyer4":'CUSTADDRESS2'}}
    dom = parse("Print.xml")
    type = dom.getElementsByTagName('DocumentID')[0].childNodes[0].nodeValue
    print type
    i = 0
    CONN_STR = 'DSN=dsn;;DB=test_DB;UID=usr;PWD=passwrd'
    db = pyodbc.connect(CONN_STR)
    c = db.cursor()
    print docTypes['INVOICE']
    if docTypes.has_key(type):
       #iterator = len(docTypes[type])
       for i in range(0,len(docTypes[type])):
          for tag in dom.getElementsByTagName(docTypes[type][i]):
             name = tag.childNodes[0]
             c.execute (u"select CUSTOMER, ADDRESSTYPE, CUSTNAME1, CUSTNAME2, CUSTADDRESS1, CUSTADDRESS2 from CUSTADDR_UC where 'CUSTOMER' = ('%u')", name.nodeValue)
             rows = c.fetchall()
             for key in changeValues[type].iterkeys():
    	        print dom.getElementsByTagName(key)[0].toxml()
    	        for row in rows:
    			   if dom.getElementsByTagName(key)[0].toxml() is not None:
    			      change = dom.getElementsByTagName(key)[0].toxml()
    			      change.nodeValue = unicode(row.BUYER1)
    open("D:\\Shantanu\\done2.xml","w").write(dom.toxml("utf-8"))


Though there is no any error in the code, it is not even replacing the node value as well. Can you please help me if anything is wrong here?
