Org.xml.sax.SAXParseException; linenumber:1; columnnumber:1; Content is not allowed in Prolog

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.