我解析了另一个程序输出的xml。从Python中的xml元素获取数据时出现问题
这里的XML片段的例子:
<result test="Passed" stamp="2011-01-25T12:40:46.166-08:00">
<assertion>MultipleTestTool1</assertion>
<comment>MultipleTestTool1 Passed</comment>
</result>
我想要得到的数据了<comment>
元素。
这里是我的代码片段:
import xml.dom.minidom
mydata.cnodes = mydata.rnode.getElementsByTagName("comment")
value = self.getResultCommentText(mydata.cnodes
def getResultCommentText(self, nodelist):
rc = []
for node in nodelist:
if node.nodeName == "comment":
if node.nodeType == node.TEXT_NODE:
rc.append(node.data)
return ''.join(rc)
值始终是空的,看来该节点类型始终是一个ELEMENT_NODE,所以.data
不存在我是新来的Python,这也是造成我挠挠我的脑袋。谁能告诉我我做错了什么?