序言中不允许出现内容
我正在尝试使用 xslt
将 xml
转换为 html。我使用 java.xml.transform 在 java 中执行此操作。 它工作正常,直到我遇到一些 xml
。它说以下错误。
[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 声明之前没有字符。我什至使用该解决方案处理了 BOM http://forums.sun.com/thread.jspa?messageID=10324562#10324562
仍然没有运气,它只发生在一个 xml 上。我什至在编辑器中打开 xml 并将其保存在使用 utf-8
编码的文件中。这让我发疯。有什么想法吗?
更新:当您为 xsl
文件提供了错误的路径并且发生文件未找到异常时,您会收到此错误。 (这是我的情况。它可能对某人有帮助。感谢您的回复)
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.
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
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?
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有一个带有 BOM 的 UTF-8 文件,并且如果您使用不知道这一点的 XML 解析器。将 XML 文件另存为 UTF-8 without 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.
你的文件中有标题吗?类似于:
这应该位于第一行的开头。不幸的是,我看不到您的 XML 文件,因为该 URL 在我所在的位置被屏蔽了。
Do you have a header in your file? Something like:
<?xml version="1.0" encoding="utf-8"?>
That should be at the start of the first line. Unfortunately I can't see your XML file as that URL is blocked from where I am.