python讀取xml內容

import os,sys
import xml.dom.minidom
def main():
    map_data = []
    print "Begain parse the %s!"%FILENAME
    os.chdir(SRC_PATH)
    ### 一級標籤
    dom = xml.dom.minidom.parse(FILENAME)
    f_sstdmap = dom.documentElement
    ### 二級標籤
    s_tag_pd = f_sstdmap.getElementsByTagName("ProductBody")
    pd = s_tag_pd[0]
    product_id = pd.firstChild.data
    s_tag_map = f_sstdmap.getElementsByTagName("Map")
    map = s_tag_map[0]
    version = map.getAttribute("Version")
    print version
    ### 三級標籤
    t_tag_notch = map.getElementsByTagName("Notch")
    notch = t_tag_notch[0]
    notch_side = notch.firstChild.data
    
    ### get total die into a list
    t_tag_dielist = map.getElementsByTagName("DieList")
    die_list = t_tag_dielist[0]
    f_tag_die = die_list.getElementsByTagName("Die")
    for item in f_tag_die:
        map_data.append((item.getAttribute('X'),item.getAttribute('y'),item.getAttribute('DIECODE'),item.getAttribute('RetX'),item.getAttribute('RetY'),item.getAttribute('RETCODE')))


參考文件

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章