• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Exception -- Content is not allowed in prolog

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to transform and xml document with an xsl stylesheet using the JSTL x:transform tag in a JSP. My import statement is:

<%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>

and the tag is used as follows:

<x:transform xml="ConcertProgram.xml" xslt="ConcertProgram.xsl"/>

When I start Tomcat and go to the JSP, I get the following exception:

javax.servlet.ServletException: [...] org.xml.sax.SAXParseException: Content is not allowed in prolog

This exception makes no sense as my XML file begins thus:

<?xml version="1.0"?>

NO content in prolog. Anyone seen this error before? Anyone found a fix for it?

Thanks
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even though you are doing this with JSTL in a JSP, I think the problem lies in the XML or XSLT files, so I'm going to move this over to the XML forum where the XSL-literate hang out.

You are probably going to need to provide the files for perusal.
 
M. Gagnon
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, I'm 99% sure it's a problem with JSTL (or perhaps Xalan) because if I specify the stylesheet in the XML file and view it in Netscape, it's perfectly ok, so the XML and XSL files are fine. I can't do that in the application for two reasons: (1) It doesn't work in IE; (2) I need other JSP content in the page, so it needs to be a JSP, not an XML file.
 
M. Gagnon
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem really was with my use of JSTL, not the XML (everything was transforming perfectly in Netscape simply by opening the XML file and specifying the XSL style sheet in that file). I'll post the solution in case anyone else has experienced the same problem.

Hardcoding the file names in the tag doesn't work:
<x:transform xml="ConcertProgram.xml" xslt="ConcertProgram.xsl"/>

You have to import the files with the c:import tag:
<c:import url="ConcertProgram.xml" var="xml" />
<c:import url="ConcertProgram.xsl" var="xsl" />
<x_rt:transform xml="${xml}" xslt="${xsl}" />

However, since my hosting service has not upgraded to Servlets 2.4/JSP 2.0, I cannot use the new Expression Language. But when I tried the following, it also did not work:

<c:import url="ConcertProgram.xml" var="xml" />
<c:import url="ConcertProgram.xsl" var="xsl" />
<x_rt:transform xml="<%= xml %>" xslt="<%= xsl %>" />

Even though I can use the scripting syntax here, the variables declared in the c:import tag are not recognized. The following does work:

<c:import url="ConcertProgram.xml" var="xml" scope="application" />
<c:import url="ConcertProgram.xsl" var="xsl" scope="application"/>
<x_rt:transform xml="<%= application.getAttribute("xml") %>" xslt="<%= application.getAttribute("xsl") %>" />

In fact, what's really great is that I can still specify the xml and xsl files in context-param tags in the deployment descriptor file for the application and access them using the following:

<c_rt:import url="<%= application.getInitParameter("concertXML") %>" var="xml" scope="application" />
<c_rt:import url="<%= application.getInitParameter("concertXSL") %>" var="xsl" scope="application" />
<x_rt:transform xml="<%= application.getAttribute("xml") %>" xslt="<%= application.getAttribute("xsl") %>" />

All that through trial and error! Ugh.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I came to this entry by Google; this is perhaps an explanation why my answer is so late.

I got the same error, trying to transform a XML file with a XSLT, using plain javax.xml.transform. After some trial and error I found that this message is only another way to say "Cannot read the XML input file".
This input file is often given as an InputStream, and the many types of InputStream allow the programmer some errors!
 
Talk sense to a fool and he calls you foolish. -Euripides A foolish tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic