java 带有“意外元素:CDATA”消息的 org.apache.xmlbeans.XmlException 是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1407101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 16:26:26  来源:igfitidea点击:

What does the org.apache.xmlbeans.XmlException with a message of "Unexpected element: CDATA" mean?

javaxmlxmlbeansxmlexception

提问by Thomas Owens

I'm trying to parse and load an XML document, however I'm getting this exception when I call the parse method on the class that extends XmlObject. Unfortunately, it gives me no ideas of what element is unexpected, which is my problem.

我正在尝试解析和加载 XML 文档,但是当我在扩展 XmlObject 的类上调用 parse 方法时出现此异常。不幸的是,它让我不知道什么元素是意外的,这是我的问题。

I am not able to share the code for this, but I can try to provide more information if necessary.

我无法为此共享代码,但如有必要,我可以尝试提供更多信息。

采纳答案by mjv

Not being able to share code or input data, you may consider the following approach. That's a very common dichotomic approach to diagnostic, I'm afraid, and indeed you may readily have started it...

无法共享代码或输入数据,您可以考虑以下方法。恐怕这是一种非常常见的二分法诊断方法,而且实际上您可能已经开始使用它了……

Try and reduce the size of the input XML by removing parts of it, ensuring that the underlying XML document remains well formed and possibly valid (if validity is required in your parser's setup). If you maintain validity, this may require to alter [a copy of] the Schema (DTD or other), as manditory elements might be removed during the cut-and-try approach... BTW, the error message seems to hint more at a validation issue that a basic well-formedness assertion issue.

尝试通过删除部分 XML 来减小输入 XML 的大小,确保底层 XML 文档保持良好的格式并且可能有效(如果解析器的设置需要有效性)。如果您保持有效性,这可能需要更改架构(DTD 或其他)的 [副本],因为在尝试的方法中可能会删除强制元素......顺便说一句,错误消息似乎更多地暗示一个验证问题,一个基本的格式良好的断言问题。

Unless one has a particular hunch as to the area that triggers the parser's complaint, we typically remove (or re-add, when things start working) about half of what was previously cut or re-added.

除非有人对触发解析器抱怨的区域有特殊的预感,否则我们通常会删除(或重新添加,当事情开始工作时)大约一半的先前删除或重新添加的内容。

You may also start with trying a mostly empty file, to assert that the parser does work at all... There again is the idea to "divide to prevail": is the issue in the XML input or in the parser ? (remembering that there could be two issues, one in the input and one in the parser, and thtat such issues could even be unrelated...)

您也可以从尝试一个几乎为空的文件开始,以断言解析器确实有效......再次出现“划分以占上风”的想法:问题是在 XML 输入中还是在解析器中?(记住可能有两个问题,一个在输入中,一个在解析器中,而且这些问题甚至可能是无关的......)

Sorry to belabor basic diagnostics techniques which you may well be fluent with...

很抱歉要详细说明您可能很熟悉的基本诊断技术...

回答by anand

You should check the arguments you are passing to the method parse(); If you are directly passing a string to parse or file or inputstream accordingly (File/InputStream/String) etc.

您应该检查传递给方法 parse() 的参数;如果您直接传递一个字符串来解析或相应地文件或输入流(文件/输入流/字符串)等。

回答by jcwhall

The exception is caused by the length of the XML file. If you add or remove one character from the file, the parser will succeed.

该异常是由 XML 文件的长度引起的。如果在文件中添加或删除一个字符,解析器将成功。

The problem occurs within the 3rd party PiccoloLexer library that XMLBeans relies on. It has been fixed in revision 959082 but has not been applied to xbean 2.5 jar.

该问题发生在 XMLBeans 所依赖的第 3 方 PiccoloLexer 库中。它已在修订版 959082 中得到修复,但尚未应用于 xbean 2.5 jar。

XMLBeans - Problem with XML files if length is exactly 8193bytes

XMLBeans - 如果长度正好是 8193 字节,则 XML 文件会出现问题

Issue reported on XMLBean Jira

XMLBean Jira 上报告的问题