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')))


参考文件

你可能感兴趣的:(python)