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

天涯浪子 提交于 2020-01-02 10:17:20

问题


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.

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


回答1:


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.

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...)

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




回答2:


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.




回答3:


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.

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 - Problem with XML files if length is exactly 8193bytes

Issue reported on XMLBean Jira



来源:https://stackoverflow.com/questions/1407101/what-does-the-org-apache-xmlbeans-xmlexception-with-a-message-of-unexpected-ele

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!