Python 为不同语言的字符串生成XML,获取错误
我正在编写代码来生成包含不同语言字符串内容的XML。最初生成unicode时我遇到了一个错误,在开始时添加了setdefault命令,现在得到的是“attributeError:'str'对象没有属性'iter'python”。我试着寻找,但答案没有多大帮助 以下是回溯: 回溯(最近一次呼叫最后一次): 请检查一下,让我知道我遗漏了什么Python 为不同语言的字符串生成XML,获取错误,python,xml,Python,Xml,我正在编写代码来生成包含不同语言字符串内容的XML。最初生成unicode时我遇到了一个错误,在开始时添加了setdefault命令,现在得到的是“attributeError:'str'对象没有属性'iter'python”。我试着寻找,但答案没有多大帮助 以下是回溯: 回溯(最近一次呼叫最后一次): 请检查一下,让我知道我遗漏了什么 File "oldgood_XliffGenerator.py", line 118, in <module> convertToXlif
File "oldgood_XliffGenerator.py", line 118, in <module>
convertToXliff(filename)
File "oldgood_XliffGenerator.py", line 47, in convertToXliff
tree.write(destifilename, xml_declaration=True, encoding='utf-8')
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 817, in write
self._root, encoding, default_namespace
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 877, in _namespaces
for elem in iterate():
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 477, in iter
for e in e.iter(tag):
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 477, in iter
for e in e.iter(tag):
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 477, in iter
for e in e.iter(tag):
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 477, in iter
for e in e.iter(tag):
AttributeError: 'str' object has no attribute 'iter'
def convertToXliff(filename):
if filename:
if os.path.isfile(filename):
valid=True
else:
print "Could not open "+filename
else:
print "no input"
global fileLength
root = ET.Element("file")
global file
file = ET.SubElement(root, "file")
file.set("id", generatingLang)
file.set("native", nativeLang)
file.set("useAsLocale", setLocale)
print "Reached stage1"
datainp = fileRead(filename)
RecurseObjects(datainp)
destifilename = "testconvfile.xml"
#Indent(root)
tree = ET.ElementTree(root)
tree.write(destifilename, xml_declaration=True, encoding='utf-8')