SAXParseException: Content is not allowed in prolog
Asked Answered
A

3

9

I need to add the following file to my Tomcat's '/conf' directory:

<?xml version="1.0" encoding="UTF-8"?>
<Context useHttpOnly="false" path="/bbc">
    <Realm className="com.bbc.tomcat.BBCSecurityRealm"/>
</Context>

After adding this file, I get the following error when Tomcat starts up"

ERROR ecmdefault util.digester.Digester 18:37:14,477 localhost-startStop-1 : Parse Fatal Error at line 1 column 1: Content is not allowed in prolog.
org.xml.sax.SAXParseException: Content is not allowed in prolog.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
    at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1427)
Antlion answered 12/12, 2013 at 18:40 Comment(1)
possible duplicate of org.xml.sax.SAXParseException: Content is not allowed in prologBalas
M
17

Your xml file has some invisible chars (most likely the BOM) at the start (before <?xml version="1.0" encoding="UTF-8"?>) which is not allowed in xml. you could view it using a hex editor. Simplest way to fix it is to create an empty text file and copy the content into it, change the extension to xml.

Check this answer for further help.

From http://www.rgagnon.com/javadetails/java-handle-utf8-file-with-bom.html

UTF8 file are a special case because it is not recommended to add a BOM to them because it can break other tools like Java. In fact, Java assumes the UTF8 don't have a BOM so if the BOM is present it won't be discarded and it will be seen as data.

Messmate answered 12/12, 2013 at 18:47 Comment(1)
Right! In my case just replacing the <?xml version="1.0" encoding="UTF-8"?> solved the issue.Almira
U
0

I had a similar issue but this reference link provided the solution spot on.

Quote from the article.

Any characters before the start of the XML content will cause above error.

org.xml.sax.SAXParseException: Content is not allowed in prolog error message.
Upswell answered 20/11, 2017 at 17:52 Comment(0)
P
0

Had this error with a line that opened with another tag than it was closed with.

I also had a double entry of one line in the xml, and I cannot trace back which of the two mistakes threw this error, but I guess it was the wrong closing tag.

Principally answered 22/1, 2023 at 21:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.