转载

XML Parser Error on line 1: Content is not allowed in prolog.

当我用s1 EPSDK36 run xsd文件时,从一个已经做好的xsd文件copy template写自己的文件时,总是报出:Content is not allowed in prolog 错误。 尝试半天结果一样,用文件对比工具问题还是得不到解决; 查询得知是BOM的问题,把文件转存为UTF-8 no BOM 格式,一切ok。 现做简单总结; ********************************************************************* 参考文档: Content is not allowed in prolog 疯了,可怜的Java 可怜的JSP,问题真多:Content is not allowed in prolog. 一个简单的JSP,转换一个XML输出HTML <c:import url="Test.xsl" var="stylesheet"/> <x:transform xslt="${stylesheet}" doc="Test.xml"/> 报错:Content is not allowed in prolog. 上网查,说可能是BOM问题,说很多编辑器保存UTF-8时会在前面加个0xFE之类的, 但是很多XML解析器又不认识。。。。 是这个原因吗?我更改了其他编码,也曾经用编辑器把0xFE去掉,没用啊。。。 其他回答: 对于UTF-8编码的文件来说, BOM头是可有可无的. 如果用dom4J加载含有BOM 头的UTF-8格式的xml文件, 却会抛出"Content is not allowed in prolog"异常. 原来无BOM头的UTF-8文件在经过UltraEdit编辑后, UltraEdit会擅自作主添加一个 BOM头(EditPlus无此问题, 记事本似乎有此问题), 即使去掉UltraEdit中与BOM相 关的所有设置选项也无济于事. 后来在UltraEdit论坛搜索答案, 有人提到11版以后 (含)的UltraEdit"另存为"对话框提供了另存为"UTF-8 - NO BOM"的一个选项.对理 想主义者来说,  这不能算是一个很完美的解决方法:( 进一步研究可以发现, IE/Windows记事本/XmlBuddy等等可正常显示含BOM头的 UTF-8格式文件.那么完美方案应该是让dom4j能正确读入含BOM头的UTF-8文件. 在dom4j的sourceforge论坛上已经有人就此提问, 但是答案中的链接已经失效. 再 次google, 在这里找到了一段代码. ///////////////////////////// 在 windows 上,檔案如果是存檔成 unicdoe 或是 utf-8 的時候,如果用 ultraedit 或是其他可以用二進元觀看檔案的軟體打開檔案,會看到檔案的開頭多了 FE FF 這 2 個位元組的東西,去年自己在玩 hibernate 時候,使用 xml 檔案做為 hibernate 初始化的設定檔,那時候曾出現一個怪問題,就是在讀取 xml 檔案的時候,xml parser 一直回報 Content is not allowed in prolog 的錯誤訊息,上網查了查資料後,才發現原來是因為檔案的前面有unicdoe 的 BOM 識別字元。 22222222222222222: http://www.blogjava.net/bigseal/archive/2005/02/27/1535.aspx "Content is not allowed in prolog" error Posted on 2005-02-27 11:09 bigseal 阅读(6046) 评论(3)  编辑  收藏 看到一篇关于在eclipse中使用ant构建java项目的文章,就按照文章中的说明新建了一个项目,并新建了classes,dist,doc,lib几个文件夹和build.xml文件。其中build.xml文件的内容也是直接复制的,由于是从网页上直接复制的,里面“<”“>”都是中文格式的,我就把这些给替换了一下。 但当选中项目,然后选择“Project”,“Properties”,“Builders”,“New…”,选择“Ant Build”:载入“Bulidfile”时提示“Content is not allowed in prolog”错误。 我就去Google上转了一圈,还有点收获,看了一篇小文章,觉得可能是build.xml文件格式的错误。 In SGML and XML, a document is composed of two sequential parts, the prolog and the instance. You can see this in an HTML example: 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " 2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " > 3 <html xmlns= "http://www.w3.org/1999/xhtml " > 4 <head > 5 <title >The Symbol Grounding Problem </title > 6 </head > 7 <body > 8 </body > 9 </html > In this example, the prolog is lines 1-2, the instance begins on line 3. The prolog includes the DOCTYPE declaration, the external subset (called the DTD), and the internal subset (which you seldom see but it 's legal). The document instance includes the document element (in this case <html > and all of its descendent content). You generally don 't want to see the prolog, and you generally don 't want to store it. The DOCTYPE declaration provides references to DTD, which is instantiated as part of the process of validating the document. You may want to store the reference(s), but you wouldn 't want to store the DTD each time you store the document, as that would be a real waste (the DTD is often bigger than the document). It sounds like your well-formed and valid document isn 't being considered as such by the XML processor. The error message indicates that there is content (i.e., either elements or character data) in the part of the document considered as the prolog. You may be missing the last " > " on line 2 above, as that would normally be the beginning of the internal subset. If it found " <html " (or something similar), you might get that error. 果然,有两个“!”是中文状态,改过来就ok 了
正文到此结束
Loading...