當我用s1 EPSDK36 run xsd文件時(shí),從一個(gè)已經(jīng)做好的xsd文件copy template寫(xiě)自己的文件時(shí),總是報出:Content is not allowed in prolog 錯誤。
嘗試半天結果一樣,用文件對比工具問(wèn)題還是得不到解決;
查詢(xún)得知是BOM的問(wèn)題,把文件轉存為UTF-8 no BOM 格式,一切ok。
現做簡(jiǎn)單總結;
*********************************************************************
參考文檔:
Content is not allowed in prolog
瘋了,可憐的Java 可憐的JSP,問(wèn)題真多:Content is not allowed in prolog.
一個(gè)簡(jiǎn)單的JSP,轉換一個(gè)XML輸出HTML
<c:import url="Test.xsl" var="stylesheet"/>
<x:transform xslt="${stylesheet}" doc="Test.xml"/>
報錯:Content is not allowed in prolog.
上網(wǎng)查,說(shuō)可能是BOM問(wèn)題,說(shuō)很多編輯器保存UTF-8時(shí)會(huì )在前面加個(gè)0xFE之類(lèi)的,
但是很多XML解析器又不認識。。。。
是這個(gè)原因嗎?我更改了其他編碼,也曾經(jīng)用編輯器把0xFE去掉,沒(méi)用啊。。。
其他回答:
對于UTF-8編碼的文件來(lái)說(shuō), BOM頭是可有可無(wú)的. 如果用dom4J加載含有BOM
頭的UTF-8格式的xml文件, 卻會(huì )拋出"Content is not allowed in prolog"異常.
原來(lái)無(wú)BOM頭的UTF-8文件在經(jīng)過(guò)UltraEdit編輯后, UltraEdit會(huì )擅自作主添加一個(gè)
BOM頭(EditPlus無(wú)此問(wèn)題, 記事本似乎有此問(wèn)題), 即使去掉UltraEdit中與BOM相
關(guān)的所有設置選項也無(wú)濟于事. 后來(lái)在UltraEdit論壇搜索答案, 有人提到11版以后
(含)的UltraEdit"另存為"對話(huà)框提供了另存為"UTF-8 - NO BOM"的一個(gè)選項.對理
想主義者來(lái)說(shuō), 這不能算是一個(gè)很完美的解決方法:(
進(jìn)一步研究可以發(fā)現, IE/Windows記事本/XmlBuddy等等可正常顯示含BOM頭的
UTF-8格式文件.那么完美方案應該是讓dom4j能正確讀入含BOM頭的UTF-8文件.
在dom4j的sourceforge論壇上已經(jīng)有人就此提問(wèn), 但是答案中的鏈接已經(jīng)失效. 再
次google, 在這里找到了一段代碼.
/////////////////////////////
在 windows 上,檔案如果是存檔成 unicdoe 或是 utf-8 的時(shí)候,如果用 ultraedit 或是其他可以用二進(jìn)元觀(guān)看檔案的軟體打開(kāi)檔案,會(huì )看到檔案的開(kāi)頭多了 FE FF 這 2 個(gè)位元組的東西,去年自己在玩 hibernate 時(shí)候,使用 xml 檔案做為 hibernate 初始化的設定檔,那時(shí)候曾出現一個(gè)怪問(wèn)題,就是在讀取 xml 檔案的時(shí)候,xml parser 一直回報 Content is not allowed in prolog 的錯誤訊息,上網(wǎng)查了查資料後,才發(fā)現原來(lái)是因為檔案的前面有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) 編輯 收藏
看到一篇關(guān)于在eclipse中使用ant構建java項目的文章,就按照文章中的說(shuō)明新建了一個(gè)項目,并新建了classes,dist,doc,lib幾個(gè)文件夾和build.xml文件。其中build.xml文件的內容也是直接復制的,由于是從網(wǎng)頁(yè)上直接復制的,里面“<”“>”都是中文格式的,我就把這些給替換了一下。
但當選中項目,然后選擇“Project”,“Properties”,“Builders”,“New…”,選擇“Ant Build”:載入“Bulidfile”時(shí)提示“Content is not allowed in prolog”錯誤。
我就去Google上轉了一圈,還有點(diǎn)收獲,看了一篇小文章,覺(jué)得可能是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.
果然,有兩個(gè)“!”是中文狀態(tài),改過(guò)來(lái)就ok 了。