Java 序言中不能有内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3395560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Content is not allowed in prolog
提问by Senthil Kumar
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.
我正在尝试xml
使用 .html转换为 html xslt
。我正在使用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.
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 声明之前没有字符。我什至使用解决方案处理 BOM 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?
仍然没有运气,它只发生在一个 xml 中。我什至在编辑器中打开了 xml 并将其保存在一个带有utf-8
编码的文件中。这真让我抓狂。任何的想法?
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)
更新:当您为xsl
文件提供了错误的路径并且发生文件未找到异常时,您会收到此错误。(这是我的情况。它可能对某人有所帮助。感谢您的回复)
回答by Jesper
回答by Noel M
Do you have a header in your file? Something like:
你的文件中有标题吗?就像是:
<?xml version="1.0" encoding="utf-8"?>
<?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.
那应该在第一行的开头。不幸的是,我无法看到您的 XML 文件,因为该 URL 已从我所在的位置被阻止。