序言中不能有内容 [英] Content is not allowed in prolog
问题描述
我正在尝试使用 xslt
将 xml
转换为html。我使用 java.xml.transform
在java中执行此操作。
它工作正常,直到我遇到一些 xml
。它说以下错误。
i'm trying to convert xml
to html using xslt
. Am using java.xml.transform
to do this in java.
it was working fine until i bumped into some xml
. it said the following error.
[Fatal Error] :1:1: Content is not allowed in prolog.
javax.xml.transform.TransformerConfigurationException:
javax.xml.transform.TransformerConfigurationException:
javax.xml.transform.TransformerException:
org.xml.sax.SAXParseException: Content is not allowed in prolog.
因此我确保在xml声明之前没有字符。我甚至使用解决方案
http:// forums来处理BOM。 sun.com/thread.jspa?messageID=10324562#10324562
so i made sure there is no character before the xml declaration. i even took care of BOM using the solution http://forums.sun.com/thread.jspa?messageID=10324562#10324562
仍然没有运气,只发生一个xml。我甚至在编辑器中打开了xml并将其保存在一个带有 utf-8
编码的文件中。这真让我抓狂。任何的想法?
STILL no luck and it happens only for one xml. i even opened the xml in editor and saved it in a file with utf-8
encoding. this is driving me crazy. any idea?
更新:当您为 xsl
文件指定错误路径并找不到文件时,会出现此错误异常发生。
(这是我的情况。它可能对某人有所帮助。感谢您的回复)
UPDATE: You get this error when you have given the wrong path for the xsl
file and a file not found exception happens.
(this was my case. it might help somebody. thanks for your responses)
推荐答案
这种事情可以如果您的UTF-8文件带有 BOM ,并且您使用的是XML解析器,则会发生不知道。将XML文件保存为UTF-8,不含BOM。
This kind of thing can happen if you have an UTF-8 file with a BOM, and if you use an XML parser that isn't aware of it. Save the XML file as UTF-8 without BOM.
这篇关于序言中不能有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!