首页 > 代码库 > [python]deteval中groundtruth.xml内容重新排序

[python]deteval中groundtruth.xml内容重新排序

#xml api:http://www.cnblogs.com/lhj588/archive/2011/11/09/2242483.html

#dictionary operations: key in dict....

from xml.dom import minidom, Node
doc = minidom.parse(‘out.xml‘)
tagset=doc.firstChild
image=tagset.firstChild
images={}
while image:
# print image.toxml()
# props=dir(image)
# print type(image)
# print type(image)
if hasattr(image,"tagName"):
# print image.tagName+":"
# print str(eval("image.%s"%"tagName"))
for imagetag in image.childNodes:

imagename=image.getElementsByTagName("imagename")[0].childNodes[0].nodeValue
images[imagename]=image

# if hasattr(imagetag,"tagName"):
# if imagetag.tagName=="imagename":
# print imagetag.toxml()

image=image.nextSibling

# for i in images.keys():
# print i

print "<tagset>"
for i in range(1,419):
imagename=str(i)+".jpg"
if images.has_key(imagename):
print imagename+"formatted"
print images[imagename].toxml()
print "</tagset>"