コード例 #1
0
def dealXML(xmlStr):
    dDb = mysql.connector.connect(host="localhost",
                                  user="******",
                                  passwd="123456",
                                  database="ghddi",
                                  auth_plugin='mysql_native_password')
    dCursor = dDb.cursor()
    domTree = xml.dom.minidom.parseString(xmlStr)
    collection = domTree.documentElement
    nodeList = collection.getElementsByTagName(TARGET_NAME)
    insertList = []
    for node in nodeList:
        tId = node.getElementsByTagName(ID_KEY)[0].childNodes[0].nodeValue
        if tId == None:
            continue
        nodeList2 = node.getElementsByTagName('ENEM01')
        for node2 in nodeList2:
            pa = node2.getElementsByTagName(
                'ENEM.PA')[0].childNodes[0].nodeValue
            pbList = node2.getElementsByTagName('ENEM.PB')
            if len(pbList) > 0:
                pb = pbList[0].childNodes[0].nodeValue
            else:
                pb = None
            insertList.append([tId, pa, pb])
        dCursor.executemany(INSERT_INTO_TABLE_ENEM_P, insertList)
        dDb.commit()
        dCursor.closeSession()
        dDb.closeSession()
    insertTM.setValue(TARGET_NAME, ID_KEY, INSERT_INTO_TABLE_ENEM, KEY_NAME)
    insertTM.dealXML(xmlStr)
コード例 #2
0
def dealXML(xmlStr):
    insertTM.setValue(TARGET_NAME, ID_KEY, INSERT_INTO_TABLE_EM, KEY_NAME)
    insertTM.dealXML(xmlStr)
コード例 #3
0
def dealXML(xmlStr):
    insertTM.setValue(TARGET_NAME, ID_KEY, INSERT_QUAN, KEY_NAME)
    insertTM.dealXML(xmlStr)