SAX Error – Content is not allowed in prolog


Working XML via SAX parser, but when it parse some XML file, it prompts following error message :

org.xml.sax.SAXParseException: Content is not allowed in prolog.
	at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
	at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)


This error message is always caused by the invalid XML content in the beginning element. For example, extra small dot “.” in the beginning of XML element.

Any characters before the “<?xml….” will cause above “org.xml.sax.SAXParseException: Content is not allowed in prolog” error message.

A small dot “.” before the “<?xml….

.<?xml version="1.0"?>
		<lastname>mook kim</lastname>
		<lastname>yin fong</lastname>
		<nickname>fong fong</nickname>

To fix it, just delete all those weird characters before the “<?xml“.

Tags :

About the Author

Founder of and, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.


  • Pingback: read more()

  • Pingback: this post()

  • Pingback: alkaline water()

  • Pingback: alkaline water()

  • Pingback: visit site()

  • Pingback: water ionizer loans()

  • Pingback: you can try these out()

  • Pingback: house blue()

  • Pingback: zak?ad szklarski piotrk√≥w trybunalski()

  • Pingback: locksmiths in zachary la()

  • Pingback: locksmith jobs in florida()

  • Pingback: local 3 electricians()

  • Pingback: electrician job outlook()

  • Pingback: alkaline water brands()

  • Pingback: water ionizer pay plan loans()

  • Pingback: pay per day loans plan()

  • Pingback: pay per day loan plans()

  • Pingback: Instagram volgers kopen()

  • Pingback: alkaline water()

  • Pingback: sms laan nu()

  • Pingback: stop parking()

  • Pingback: car parking()

  • Pingback: lan penge nu uden renter()

  • Pingback: 3gp mobile porn()

  • Pingback: best DIRECTV deals()

  • Pingback: Tanner deep throat()

  • Pingback: watch movies online free()

  • Pingback: watch tv show episodes()

  • Pingback: Blue Coaster33()

  • Faisal Basra

    what if I am parsing the XML from URL not from file? So I can’t modify the content in URL?

  • sharath

    Thank you so much, mk-young is mini google for me. Hats off to u sir

  • test

    Hi All
    Check Encoding “UTF-8 without BOM” in notepad++
    if nothing is there b4

  • chitra

    U r really genious man, what ever im searching for, im getting from u only, thanks guru

  • Vishal

    I am facing the same issue. XML is below,

    • Vishal
    • Vishal
      &lt;?xml version=&quot;1.0&quot;?&gt;
      &lt;!DOCTYPE FCCFT SYSTEM &quot;./FCCFT.DTD&quot;&gt;
      • Vishal
        public static void main(String[] args) {
        	String p_message = &quot;&lt;?xml version=\&quot;1.0\&quot;?&gt;&quot;+
        			&quot;&lt;!DOCTYPE FCCGENERIC SYSTEM \&quot;./FCCGENERIC.DTD\&quot;&gt;&quot;+
        	DOMParser domParser = null;
        	Document  xmlDocument;
        	Element documentElement;
        	StringReader	l_reader 	= null;
        	InputSource	l_in_source	= null;
        	if (domParser == null) {		
        	domParser	= new DOMParser ();
        	try {
        	l_reader	= new StringReader (p_message);
        	l_in_source = new InputSource (l_reader);
        	domParser.parse (l_in_source);
        	l_reader.close ();
        	xmlDocument		= domParser.getDocument ();
        	documentElement	= xmlDocument.getDocumentElement ();
        } finally {
        	try {
        	l_reader.close ();
        } catch (Exception e1) {
        	l_reader	= null;
        	l_in_source	= null;
    • vijay

      awesome wasted almost half an hour for this silly typing mistake..

  • apoorva

    Hi Mkyong,
    I am facing the same error. I check my xml file to ensure that it doesn’t contain any invalid characters but I am still facing the same error. Here is my xml file content:

    &lt;?xml version=&quot;1.0&quot; ?&gt;

    And following is the java code I am using

    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
    import org.xml.sax.Attributes;
    import org.xml.sax.SAXException;
    import org.xml.sax.helpers.DefaultHandler;
    public class SurveyParser {
    	public static void main(String[] args) {
            try {
    			    InputStream xmlInput = new FileInputStream(&quot;C:/Users/kumarap/sampleData2.xml&quot;);
    			    SAXParserFactory factory = SAXParserFactory.newInstance();
    	            SAXParser saxParser = factory.newSAXParser();
    	            SaxHandler handler   = new SaxHandler();
    	            if(xmlInput.available() &gt; 0){
    	            	saxParser.parse(xmlInput, handler);
    	            	//Let's print the values
    		   }catch (Exception e) {

    And the stack trace of exception is:

    org.xml.sax.SAXParseException: Content is not allowed in prolog.
    at javax.xml.parsers.SAXParser.parse(
    at javax.xml.parsers.SAXParser.parse(

  • Pingback: Java XML Tutorials()