简体   繁体   English

xml.etree.ElementTree.ParseError:文档元素后出现垃圾

[英]xml.etree.ElementTree.ParseError: junk after document element

I'm trying to install CESM2 and while trying to create a new case I receive this error:我正在尝试安装 CESM2,并在尝试创建新案例时收到此错误:

 File "/usr/lib64/python3.6/xml/etree/ElementTree.py", line 1196, in parse tree.parse(source, parser) File "/usr/lib64/python3.6/xml/etree/ElementTree.py", line 597, in parse self._root = parser._parse_whole(source) xml.etree.ElementTree.ParseError: junk after document element: line 211, column 2

When I traced back line 211 in ElementTree.py, it contains this function:当我在 ElementTree.py 中追溯第 211 行时,它包含这个 function:

def __bool__(self):
    warnings.warn(
        "The behavior of this method will change in future versions.  "
        "Use specific 'len(elem)' or 'elem is not None' test instead.",
        FutureWarning, stacklevel=2
        )
    return len(self._children) != 0 # emulate old behaviour, for now

Can anyone please suggest how to resolve this?谁能建议如何解决这个问题?

The indicated position ( line 211, column 2 ) refers to the source file being parsed, not the line in your code.指示的 position (第 211 行,第 2 列)是指正在解析的文件,而不是代码中的行。

When parsing XML file, it should contain a single element at the top level.解析 XML 文件时,它应该在顶层包含一个元素。 Apparently your source XML is malformed.显然您的源 XML 格式不正确。

Sometimes a solution in this case is to "wrap" the whole content with a single "root" element.有时,这种情况下的解决方案是用单个“根”元素“包装”整个内容。 At least this parsing error should disappear, but note that it changes the output XML tree, compared to the original intention, so maybe some XPath expressions should be also changed.至少这个解析错误应该消失了,但是注意它改变了 output XML 树,与初衷相比,所以可能一些 XPath 表达式也应该改变。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在 Python 中解析 XML 文件 - xml.etree.ElementTree.ParseError - Cannot parse XML files in Python - xml.etree.ElementTree.ParseError 'xml.etree.ElementTree.ParseError: no element found' 制作 python class 时 - 'xml.etree.ElementTree.ParseError: no element found' when making python class xml.etree.ElementTree.ParseError -- 异常处理未捕获错误 - xml.etree.ElementTree.ParseError -- exception handling not catching errors 修复 xml.etree.ElementTree.ParseError: undefined entity è - Fixing xml.etree.ElementTree.ParseError: undefined entity &egrave Python XML:ParseError:文档元素之后的垃圾 - Python XML: ParseError: junk after document element 尝试使用 PY3 从 XML 中提取数据时出现 xml.etree.ElementTree.ParseError 问题 - xml.etree.ElementTree.ParseError issue when trying to extract data from XML using PY3 尝试使用python解析xml时出错:xml.etree.ElementTree.ParseError:语法错误:第1行 - Error trying parsing xml using python : xml.etree.ElementTree.ParseError: syntax error: line 1, xml python prasing 3错误(xml.etree.ElementTree.ParseError:格式不正确(无效令牌):第1行,第2列) - xml prasing in python 3 errors (xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 2) xml.etree.ElementTree.ParseError: unbound prefix: 如何在不对 xml 文件进行任何更改的情况下解决此问题 - xml.etree.ElementTree.ParseError: unbound prefix: How to solve this issue without making any change to xml file xml.etree.ElementTree.ParseError:格式不正确(无效令牌):第104行,第109列 - xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 104, column 109
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM