文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>python parse xml

python parse xml

时间:2010-05-12  来源:terry-xcb

#!/usr/bin/python import sys
from xml.dom import minidom
def findNode( in_parent, in_nodeName):
    """
    check wether the child node exist from paraent xml tree
    """
    if in_parent:
        for node in in_parent.childNodes:
            if node.nodeType == node.ELEMENT_NODE:
                if node.nodeName == in_nodeName:
                    return node
if __name__=="__main__":
    xml_fd   = minidom.parse('./b.xml')
    TargetBD = findNode(xml_fd, 'TargetBD')     if(TargetBD == None):
       sys.exit(0)
    softwareReleaseVersion = TargetBD.getAttribute('softwareReleaseVersion')
    commandScriptName = TargetBD.getAttribute('commandScriptName')
    buildDescriptorId = TargetBD.getAttribute('buildDescriptorId')
    print softwareReleaseVersion
    print commandScriptName
    print buildDescriptorId
    buildElement = findNode(TargetBD, 'buildElement')
    if(buildElement == None):
       sys.exit(0)
    ElementCounts = TargetBD.getElementsByTagName("buildElement")
    for element in ElementCounts:
        softwareReleaseType = element.getAttribute('softwareReleaseType')
        softwareReleaseId = element.getAttribute('softwareReleaseId')
        softwareArchiveName = element.getAttribute('softwareArchiveName')
        print softwareReleaseType
        print softwareReleaseId
        print  softwareArchiveName
========================================================================
  xml ================================ <?xml version="1.0" encoding="UTF-8"?>
<TargetBD softwareReleaseVersion='Q3 1.2-0 RNXENVQ3 1.2-0' buildDescriptorId='Q3 1.2-0 RNXENVQ3 1.2-0 Q3060602' commandScriptName='SCRIPT.ZIP'>
<buildElement softwareReleaseType='Full Release' softwareReleaseId='Q3060600' softwareArchiveName='Q3060600.ZIP' softwareReleaseDate='18/09/2007' newFlag='.T.'>
</buildElement>
<buildElement softwareReleaseType='Change Delivery' softwareReleaseId='Q3060601' softwareArchiveName='Q3060601.ZIP' softwareReleaseDate='20/09/2007' newFlag='T'>
</buildElement>
<buildElement softwareReleaseType='Change Delivery' softwareReleaseId='Q3060602' softwareArchiveName='Q3060602.ZIP' softwareReleaseDate='26/09/2007' newFlag='T'>
</buildElement>
</TargetBD>  
相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载