This exception occurs when you read an XML file with sax, and you can see it in general on the Internet:
1.BOM
Test the InputStream in Java to see if there is a BOM that can be used with Apache Commons io Org.apache.commons.io.input.BOMInputStream, if your project has the introduction of IO
The basic knowledge of BOM can be consulted: http://www.unicode.org/faq/utf_bom.html
Also put a small way to filter the BOM
private static InputStream Checkforutf8bomanddiscardifany (InputStream inputstream) throws IOException { Pushbackinputstream Pushbackinputstream = new Pushbackinputstream (new Bufferedinputstream (InputStream), 3); Byte[] BOM = new Byte[3]; if (Pushbackinputstream.read (BOM)! =-1) { if (!) ( Bom[0] = = (byte) 0xEF && bom[1] = = (byte) 0xBB && bom[2] = = (byte) 0xBF)) { Pushbackinputstream.unread (BOM); } } return pushbackinputstream; }
2. Non-structured XML content, such as illegal characters appearing before <?xml
You can use regular <?xml to start capturing content from the
3. Today I found out because: accept-encoding enabled compression transmission, you can try to set accept-encoding: identity, but also pay attention to whether to use chunked Transfer Encoding ( Segmented transfer)
Something, some say that the direct spread to SAX parser can be filtered out. Of course I used the SAX,JAXP found not to filter out. Environment for document testing: Java 7 + xerces sax. All exception stacks
Org.xml.sax.SAXParseException; linenumber:1; columnnumber:1; 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) at Org.apache.xerces.impl.XMLErrorReporter.reportError (Unknown Source) at Org.apache.xerces.impl.XMLErrorReporter.reportError (Unknown Source) at Org.apache.xerces.impl.XMLScanner.reportFatalError (Unknown Source) at Org.apache.xerces.impl.xmldocumentscannerimpl$prologdispatcher.dispatch (Unknown Source) at Org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument (Unknown Source) at Org.apache.xerces.parsers.XML11Configuration.parse (Unknown Source) at Org.apache.xerces.parsers.XML11Configuration.parse (Unknown Source) at Org.apache.xerces.parsers.XMLParser.parse ( Unknown source) at Org.apache.xerces.parsers.AbstractSAXParser.parse (Unknown source) at Org.apache.xerces.jaxp.sAxparserimpl$jaxpsaxparser.parse (Unknown source) at Org.apache.xerces.jaxp.SAXParserImpl.parse (Unknown source)
Org.xml.sax.SAXParseException; linenumber:1; columnnumber:1; Content is not allowed in Prolog