11

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)

CAMOBAP
  • 5,523
  • 8
  • 58
  • 93
Senthil Kumar
  • 9,695
  • 8
  • 36
  • 45
  • 1
    show the XML file (upload somewhere) – Bozho Aug 03 '10 at 10:24
  • It might help to know something about the xml file. Can you paste it (or some of it)? – Marcelo Cantos Aug 03 '10 at 10:25
  • @Bozho and @Marcelo uploaded the file at http://www.2shared.com/document/tbf2IXUy/test2.html – Senthil Kumar Aug 03 '10 at 10:50
  • I think it would be better if the XML (or maybe just the relevant part of it) is in the question - this way the question can be taken as a whole, without having to leave the page. – Noel M Aug 03 '10 at 11:16
  • Answers by both Noel & Jesper were helpful. Help me choose the right answer guys. I cant decide as the prob wasn't in xml or xsl but xsl file path. – Senthil Kumar Aug 26 '10 at 10:33
  • possible duplicate of [org.xml.sax.SAXParseException: Content is not allowed in prolog](http://stackoverflow.com/questions/5138696/org-xml-sax-saxparseexception-content-is-not-allowed-in-prolog) – Raedwald Jul 18 '14 at 09:23

2 Answers2

6

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.

Jesper
  • 202,709
  • 46
  • 318
  • 350
4

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.

Noel M
  • 15,812
  • 8
  • 39
  • 47