我一直在尝试使用 Python 解析 XML,并且发现在我的 XML 标记中出现拼写错误会引发ExpatError
. 由于我不认为我的代码驻留在国外,ExpatError
一般来说,指的是什么?
拼写错误的代码:
minidom.parseString("<people><pesron>Dan</person><person>John</person></people>")
结果是:
ExpatError Traceback (most recent call last)
<ipython-input-5-9c00296c48cb> in <module>()
----> 1 minidom.parseString("<people><pesron>Dan</person><person>John</person></people>")
/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/xml/dom/minidom.pyc in parseString(string, parser)
1928 if parser is None:
1929 from xml.dom import expatbuilder
-> 1930 return expatbuilder.parseString(string)
1931 else:
1932 from xml.dom import pulldom
/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/xml/dom/expatbuilder.pyc in parseString(string, namespaces)
938 else:
939 builder = ExpatBuilder()
--> 940 return builder.parseString(string)
941
942
/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/xml/dom/expatbuilder.pyc in parseString(self, string)
221 parser = self.getParser()
222 try:
--> 223 parser.Parse(string, True)
224 self._setup_subset(string)
225 except ParseEscape:
ExpatError: mismatched tag: line 1, column 21