我的 XML 文件 test.xml 包含以下标签
<?xml version="1.0" encoding="ISO-8859-1"?>
<AppName>
<author>Subho Halder</author>
<description> Description</description>
<date>2012-11-06</date>
<out>Output 1</out>
<out>Output 2</out>
<out>Output 3</out>
</AppName>
<out>
我想计算标签出现的次数
到目前为止,这是我编写的 python 代码:
from xml.dom.minidom import parseString
file = open('test.xml','r')
data = file.read()
file.close()
dom = parseString(data)
if (len(dom.getElementsByTagName('author'))!=0):
xmlTag = dom.getElementsByTagName('author')[0].toxml()
author = xmlTag.replace('<author>','').replace('</author>','')
print author
有人可以帮我吗?