xml.parsers.expat.ExpatError:格式不正确(令牌无效):第29行,第22列

时间:2018-09-29 14:06:42

标签: python xml python-3.6

上次我尝试从xml文件中读取一些信息。我之前在另一个应用程序中做了这个。因此,我重复了这些步骤,但是这次没有用。我看到这个错误:

xml.parsers.expat.ExpatError: not well-formed (invalid token): line 29, column22

完整引用:

    Traceback (most recent call last):
  File "C:/Users/piotr/PycharmProjects/Projekt/Api/DEdit/DEdit/DEdit.pyw", line 280, in <module>
    ui.setupUi(MainWindow)
  File "C:/Users/piotr/PycharmProjects/Projekt/Api/DEdit/DEdit/DEdit.pyw", line 178, in setupUi
    self.read_keywords_from_xml()
  File "C:/Users/piotr/PycharmProjects/Projekt/Api/DEdit/DEdit/DEdit.pyw", line 258, in read_keywords_from_xml
    xml_doc = minidom.parse(way)
  File "C:\Python\lib\xml\dom\minidom.py", line 1958, in parse
    return expatbuilder.parse(file)
  File "C:\Python\lib\xml\dom\expatbuilder.py", line 911, in parse
    result = builder.parseFile(fp)
  File "C:\Python\lib\xml\dom\expatbuilder.py", line 207, in parseFile
    parser.Parse(buffer, 0)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 29, column 22

我使用极简主义

def read_keywords_from_xml(self):
    way = api.find_way_to_file(self,"keywords.xml")
    print(way)
    xml_doc = minidom.parse(way)

    self.xmldata.append([])
    # While to takes elements from xml file
    for item in xml_doc.getElementsByTagName('keywords')[0].getElementsByTagName("item"):
        self.xmldata[0].append(item.attributes["word"].value)
    self.xmldata.append([])
    for item in xml_doc.getElementsByTagName('operators')[0].getElementsByTagName("item"):
        self.xmldata[1].append(item.attributes["symbol"].value)
    self.xmldata.append([])
    for item in xml_doc.getElementsByTagName('braces')[0].getElementsByTagName("item"):
        self.xmldata[2].append(item.attributes["key"].value)
    self.xmldata.append([])
    for item in xml_doc.getElementsByTagName('function')[0].getElementsByTagName("item"):
        self.xmldata[3].append(item.attributes["func"].value)
    self.xmldata.append([])

也许有人知道我该如何解决?

其余代码:https://github.com/VarusEx/DEdit/tree/Read_keywords_from_Xml

0 个答案:

没有答案