Python:Minidom parseString 格式不正确

问题描述

在尝试使用 minidom 和 ElementTree 解析和字符串时,我遇到了格式不正确的错误在这两种情况下,当它关闭第二个属性 ()

时都会发生

这是我的代码

from xml.dom import minidom
import xml.etree.ElementTree as ET

data = minidom.parseString("<happy>Lennox has always truly wanted to fight for the world title and was happy <cause>taking the tough route<\cause> . <\happy>")

错误

ExpatError                                Traceback (most recent call last)
<ipython-input-23-eda56dc52723> in <module>
----> 1 data = minidom.parseString("<happy>Lennox has always truly wanted to fight for the world title and was happy <cause>taking the tough route<\cause> . <\happy>")

~/anaconda3/envs/nlg_emotions/lib/python3.6/xml/dom/minidom.py in parseString(string,parser)
   1966     if parser is None:
   1967         from xml.dom import expatbuilder
-> 1968         return expatbuilder.parseString(string)
   1969     else:
   1970         from xml.dom import pulldom

~/anaconda3/envs/nlg_emotions/lib/python3.6/xml/dom/expatbuilder.py in parseString(string,namespaces)
    923     else:
    924         builder = ExpatBuilder()
--> 925     return builder.parseString(string)
    926 
    927 

~/anaconda3/envs/nlg_emotions/lib/python3.6/xml/dom/expatbuilder.py in parseString(self,string)
    221         parser = self.getParser()
    222         try:
--> 223             parser.Parse(string,True)
    224             self._setup_subset(string)
    225         except ParseEscape:

ExpatError: not well-formed (invalid token): line 1,column 111

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)