尝试使用 minidom 和 ElementTree 解析和字符串时出现格式错误且格式不正确的错误。在这两种情况下,当它关闭第二个属性(<\cause>)时都会发生
这是我的代码
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