The cause of the "Content is not allowed in prolog" error we had on AIX turned out to be a bad application properties file on that box. The property specifying the location of the sql mapping config file got run together with a comment line above it. My theory is that when the property value was unsuccessfully substituted in the dao.xml file, the bad sql mapping config file location was given to the parser which resulted in the misleading "Content is not allowed in prolog" error. It was not that it couldn't parse the sql config mapping file, it actually couldn't find it. I don't know why we didn't see a different error message.
We opened a ticket with IBM while we tried to figure this out. IBM had the following say about the iBatis code. Although IBM was mistaken about the cause of the error, they pointed out some things about the iBatis code that might be worth looking into: "I've taken a deeper look and it appears that iBatis is at fault. In the PMR log I noticed the following trace: [6/21/05 9:33:41:994 CDT] 53749a3f WebGroup E SRVE0026E: [Servlet Error]-[Error while configuring DaoManager. Cause: com.ibatis.common.exception.NestedRuntimeException: Error occurred. Cause: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: org.xml.sax.SAXParseException: Content is not allowed in prolog. Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog. Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: org.xml.sax.SAXParseException: Content is not allowed in prolog. . 6/22/05 13:27:46:202 CDT] 55951fa2 RequestProces W org.apache.struts.action.RequestProcessor Unhandled Exception thrown: class com.ibatis.dao.client.DaoException and then found the source (in Apache) in the com.ibatis.common.xml.NodeletParser [1] class which throws the com.ibatis.common.xml.NodeletException [2]. NodeletParser, specifically the method NodeletParser.createDocument(Reader) passes a java.io.Reader to the parser as an input. This is the problem. When the parser reads from an InputStream or from a URL it determines the encoding of the document from the XML declaration (i.e. <?xml version="1.0" encoding="ISO-8859-1"?>) and then chooses the appropriate java.io.Reader to use for that encoding. iBatis doesn't give the parser the chance to pick the proper java.io.Reader for the document since it provides the Reader directly. The java.io.Reader which is passed to the parser is a java.io.InputStreamReader created by com.ibatis.common.resources.Resources [3] from SqlMapConfigParser.addSqlMapNodelets() [4]. The javadoc for the constructor of InputStreamReader [5] which the Resources class uses says: "Create an InputStreamReader that uses the default charset." I guess this is working on Windows because the default encoding just happens to be the same as (or is compatible with) the encoding of the document. On AIX it would seem like this is not the case, so it fails. Because the default encoding varies from platform to platform creating an InputStreamReader with the default encoding is always a bug waiting to happen. [1] http://svn.apache.org/viewcvs.cgi/ibatis/trunk/java/mapper/mapper2/src/c om/ibatis/common/xml/NodeletParser.java?rev=180318&view=markup [2] http://svn.apache.org/viewcvs.cgi/ibatis/trunk/java/mapper/mapper2/src/c om/ibatis/common/xml/NodeletException.java?rev=180318&view=markup [3] http://svn.apache.org/viewcvs.cgi/ibatis/trunk/java/mapper/mapper2/src/c om/ibatis/common/resources/Resources.java?rev=180318&view=markup [4] http://svn.apache.org/viewcvs.cgi/ibatis/trunk/java/mapper/mapper2/src/c om/ibatis/sqlmap/engine/builder/xml/SqlMapConfigParser.java?rev=180318&v iew=markup [5] http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStreamReader.html#I nputStreamReader(java.io.InputStream) Thanks, Paul McAdams IBM WebSphere Application Server Support" -----Original Message----- From: Larry Meadors [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 22, 2005 11:03 AM To: user-java@ibatis.apache.org Subject: Re: Content is not allowed in prolog This really is not an iBATIS issue, but I suspect you must need to somehow edit the XML in a plain text editor, and make sure there are no unicode charaters in it, and that the very first line begins with <?xml - on the first line with no spaces before it. On 6/22/05, Mitchell, Steven C <[EMAIL PROTECTED]> wrote: > > We recently starting developing with iBatis (I have used it before at > other sites). It runs fine on a WebSphere 5.1 under Rational > Application Developer 6.0 on Windows XP; however, when we try to > deploy to WebSphere 5.1 on AIX iBatis will not load and we get the > following error: > > > Error 500: Error while configuring DaoManager. Cause: > com.iBatis.common.exception.NestedRuntimeException: Error occurred. > Cause: com.ibatis.common.xml.NodeletException: > Error parsing XML. Cause: org.xml.sax.SAXParseException: Content is > not allowed in prolog. Caused by: org.xml.sax.SAXParseException: > Content is not allowed in prolog. Caused by: > com.ibatis.common.xml.NodeletException: Error parsing XML. > Cause: org.xml.sax.SAXParseException: Content is not allowed in > prolog. Caused by: org.xml.sax.SAXParseException: Content is not > allowed in prolog. One of my team members found this link about a bug > in RAD 6.0 where it writes a bad Byte Offset Mark (BOM) in XML files > (http://forum.java.sun.com/thread.jspa?threadID=567285&tstart=90), > so we implemented the recommended circumvention on all the iBatis XML > files and switched from UTF-8 to ISO-8859-1 encoding. We still get the > error. > > Has anybody else had this problem? Any suggestions?