org.xml.sax.SAXParseException: Content is not allowed in prolog

sax错误:org.xml.sax.SAXParseException: Content is not allowed in prolog解决  
标签: org. xml. sax. saxparse exception content is not allowed in prolog 分类: 开发技术之java
原因及其解决办法:

1.xml编码错误

该xml是UTF-8编码的,如果该文件通过UltraEdit编辑后,会在无BOM头的UTF-8文件中加入BOM,但是DOM4j不认这个BOM(dom4j1.3),解决的办法可以通过升级dom4j到1.6解决www.dom4j.org

什么是BOM?http://www.unicode.org/faq/utf_bom.html#22Unicode规范中有一个BOM的概念。BOM——Byte Order Mark,就是字节序标记。在这里找到一段关于BOM的说明:

在UCS 编码中有一个叫做"ZERO WIDTH NO-BREAK SPACE"的字符,它的编码是FEFF。而FFFE在UCS中是不存在的字符,所以不应该出现在实际传输中。UCS规范建议我们在传输字节流前,先传输字符"ZERO WIDTH NO-BREAK SPACE"。这样如果接收者收到FEFF,就表明这个字节流是Big-Endian的;如果收到FFFE,就表明这个字节流是Little-Endian的。因此字符"ZERO WIDTH NO-BREAK SPACE"又被称作BOM。

UTF-8不需要BOM来表明字节顺序,但可以用BOM来表明编码方式。字符"ZERO WIDTH NO-BREAK SPACE"的UTF-8编码是EF BB BF。所以如果接收者收到以EF BB BF开头的字节流,就知道这是UTF-8编码了。

Windows就是使用BOM来标记文本文件的编码方式的。

2.xml文件存在非法字符

把xml 动手敲一遍,删除不该有的间隔符:比如空格,制表符(TAB)等。

异常提示是Content is not allowed in prolog.意思就是说文件开头的时候有问题。

怎么去掉BOM:

首先windows自带的记事本会在保存UTF-8编码的文件时不管是否含有BOM一律加上BOM,所以千万别用记事本。比较新版本的UltraEdit(以下简称UE,大家都是这么叫的)都对BOM支持比较好,所以推荐使用新版本的UE来解决这个问题。我用的版本是UltraEdit-32 11.00a+中文版。首先打开UE,选择菜单栏“高级”-“配置”,出现一个选项卡窗口,在“常规”选项卡中找到“保存时对所有UTF-8文件头标记(BOM)”和“对在UltraEdit里创建的新文件写入UTF-8文件头标记(如上面)”,把它们的复选框都取消不选,然后确定。这个时候UE默认情况下就不会对没有BOM的文件加入BOM,注意如果不执行上述操作UE默认也是会加的!那已经含有BOM的文件如何清除BOM呢?下面演示给大家。首先打开文件,选择菜单栏“文件”-“格式转换”-“UTF-8 转 ASCII”,这样文件会被转为ASCII编码,BOM就不会存在了,因为上面说过BOM是在UCS编码的头部的,然后再选择菜单栏“文件”-“格式转换”-“ASCII 转 UTF-8(Unicode编辑)”,这个时候文件会被转回为UTF-8编码,因为我们上面选了不自动加BOM,所以这个时候的文件是不带BOM的,然后保存文件。整个操作过程就完毕了。

转载自:http://blog.sina.com.cn/s/blog_6d5d8b580100txon.html

时间: 2024-08-29 11:17:38

org.xml.sax.SAXParseException: Content is not allowed in prolog的相关文章

转载:sax错误:org.xml.sax.SAXParseException: Content is not allowed in prolog解决

原因及其解决办法: 1.xml编码错误 该xml是UTF-8编码的,如果该文件通过UltraEdit编辑后,会在无BOM头的UTF-8文件中加入BOM,但是DOM4j不认这个BOM(dom4j1.3),解决的办法可以通过升级dom4j到1.6解决www.dom4j.org 什么是BOM?http://www.unicode.org/faq/utf_bom.html#22Unicode规范中有一个BOM的概念.BOM——Byte Order Mark,就是字节序标记.在这里找到一段关于BOM的说明

tom启动报错:org.xml.sax.SAXParseException: Content is not allowed in prolog.

警告: Catalina.start using conf/server.xml: org.xml.sax.SAXParseException: Content is not allowed in prolog. at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1231) at com.sun.org.apache.xerces.internal.jaxp.S

sax错误:org.xml.sax.SAXParseException: Content is not allowed in prolog解决

原因及其解决办法: (转载自http://blog.sina.com.cn/s/blog_6d5d8b580100txon.html) 1.xml编码错误 该xml是UTF-8编码的,如果该文件通过UltraEdit编辑后,会在无BOM头的UTF-8文件中加入BOM,但是DOM4j不认这个BOM(dom4j1.3),解决的办法可以通过升级dom4j到1.6解决www.dom4j.org 什么是BOM?http://www.unicode.org/faq/utf_bom.html#22Unicod

Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in

1.错误描述 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 1 in XML document from file [E:\Ecl

org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog

用sax读xml文件时常会出现这个异常,一般上网可以看到的原因是: 1.BOM 在java中测试inputstream中是否有bom可以用apache commons IO 的org.apache.commons.io.input.BOMInputStream,如果你的项目有引入IO的情况下 BOM的基础知识可以参考:http://www.unicode.org/faq/utf_bom.html 也贴一个过滤BOM的小方法 private static InputStream checkForU

Cause: org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup.

Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup.    at org.apache.ibatis.parsing.XPathParser.

Caused by: org.xml.sax.SAXParseException: The content of elements must consist of well-formed charac

启动tomcat后,console报错如下: Caused by: org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup. 由于这种错误都犯了几次,现在把问题记录下来. 第一种产生的原因是:sql中的大于号(>)或(<)小于号没有进行转义. XML只有5个转义符:<,>,&,",?;的转义字符分别如下:

Line 23 in XML document from class path resource [spring-mvc.xml] is invalid; nested exception is org.xml.sax.SAXParseException:

今天在把自己的项目转为maven架构的时候,居然碰到了一个很奇葩的问题具体如下: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 23 in XML document from class path resource [spring-mvc.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cos-all-l

org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。

二月 25, 2016 9:24:24 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin 警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SpringMvc-1' did not find a matching property. 二月 25,