本文介绍了关于SAXparseException:序言中不允许内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用glassfish服务器,并且不断出现以下错误:
I am using glassfish server and the following error keeps coming:
Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
at com.sun.enterprise.deployment.io.DeploymentDescriptorFile.read(DeploymentDescriptorFile.java:304)
at com.sun.enterprise.deployment.io.DeploymentDescriptorFile.read(DeploymentDescriptorFile.java:226)
at com.sun.enterprise.deployment.archivist.Archivist.readStandardDeploymentDescriptor(Archivist.java:480)
at com.sun.enterprise.deployment.archivist.Archivist.readDeploymentDescriptors(Archivist.java:305)
at com.sun.enterprise.deployment.archivist.Archivist.open(Archivist.java:213)
at com.sun.enterprise.deployment.archivist.ApplicationArchivist.openArchive(ApplicationArchivist.java:813)
at com.sun.enterprise.instance.WebModulesManager.getDescriptor(WebModulesManager.java:395)
... 65 more
推荐答案
选中此链接
简而言之,某些XML文件的前端(紧接在<?xml ...?>
之前)包含三字节模式(0xEF 0xBB 0xBF),即UTF-8字节顺序标记.Java的默认XML解析器无法处理这种情况.
In short, some XML file contains the three-byte pattern (0xEF 0xBB 0xBF) at the front (right before <?xml ...?>
), which is the UTF-8 byte order mark. The java's default XML parser can't handle this case.
快速而肮脏的解决方案是删除XML文件开头的空白:
The quick and dirty solution is to remove the white space at the front of the XML file:
String xml = "<?xml ...";
xml = xml.replaceFirst("^([\\W]+)<","<");
请注意,由于String.trim()仅修整了有限的空白字符,因此还不够.
note that the String.trim() dost not enough, since it only trim the limited whitespace characters.
这篇关于关于SAXparseException:序言中不允许内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!