序言中不允许出现内容

发布于 2024-09-12 18:57:18 字数 839 浏览 12 评论 0原文

我正在尝试使用 xsltxml 转换为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玩心态 2024-09-19 18:57:18

如果您有一个带有 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.

凤舞天涯 2024-09-19 18:57:18

你的文件中有标题吗?类似于:

这应该位于第一行的开头。不幸的是,我看不到您的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文