将Python ElementTree转换为字符串 [英] Convert Python ElementTree to string
本文介绍了将Python ElementTree转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每当我呼叫ElementTree.tostring(e)
时,都会收到以下错误消息:
Whenever I call ElementTree.tostring(e)
, I get the following error message:
AttributeError: 'Element' object has no attribute 'getroot'
还有其他方法可以将ElementTree对象转换为XML字符串吗?
Is there any other way to convert an ElementTree object into an XML string?
TraceBack:
TraceBack:
Traceback (most recent call last):
File "Development/Python/REObjectSort/REObjectResolver.py", line 145, in <module>
cm = integrateDataWithCsv(cm, csvm)
File "Development/Python/REObjectSort/REObjectResolver.py", line 137, in integrateDataWithCsv
xmlstr = ElementTree.tostring(et.getroot(),encoding='utf8',method='xml')
AttributeError: 'Element' object has no attribute 'getroot'
推荐答案
Element
对象没有.getroot()
方法.删除该呼叫,然后 .tostring()
通话有效:
Element
objects have no .getroot()
method. Drop that call, and the .tostring()
call works:
xmlstr = ElementTree.tostring(et, encoding='utf8', method='xml')
这篇关于将Python ElementTree转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文