微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python:Minidom parseString 格式不正确

如何解决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 举报,一经查实,本站将立刻删除。