#!/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
================================
阅读(870) | 评论(0) | 转发(0) |