Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Content is not allowed in prolog

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)

like image 882
Senthil Kumar Avatar asked Aug 03 '10 10:08

Senthil Kumar


People also ask

What does it mean content is not allowed in prolog?

Problem: You received the error message, “Content is not allowed in prolog.” The result of this error is that one or more files will not process in eFORMz. Solution: You must remove the content from the prolog.

What is prolog in XML?

The prolog consists of an XML declaration, possibly followed by a document type declaration. The body is made up of a single root element, possibly with some comments and/or processing instructions. An XML document is typically a computer file whose contents meet the requirements laid out in the XML specification.

What is the XML declaration?

The XML Declaration provides basic information about the format for the rest of the XML document. It takes the form of a Processing Instruction and can have the attributes version, encoding and standalone.


2 Answers

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.

like image 129
Jesper Avatar answered Sep 23 '22 19:09

Jesper


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.

like image 34
Noel M Avatar answered Sep 23 '22 19:09

Noel M