将Python ElementTree转换为string
我读过文档,我知道它有关于ElementTree.tostring(e)
但每当我打电话,我得到以下错误信息:
AttributeError: 'Element' object has no attribute 'getroot'
有没有其他的方法来将ElementTree对象转换为XMLstring?
追溯:
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()
调用起作用:
xmlstr = ElementTree.tostring(et, encoding='utf8', method='xml')