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 了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM