Content is not allowed in Prolog SAXParserException

212,076

Solution 1

This error is probably related to a byte order mark (BOM) prior to the actual XML content. You need to parse the returned String and discard the BOM, so SAXParser can process the document correctly.

You will find a possible solution here.

Solution 2

to simply remove it, paste your xml file into notepad, you'll see the extra character before the first tag. Remove it & paste back into your file - bof

Solution 3

Check the XML. It is not a valid xml.

Prolog is the first line with xml version info. It ok not to include it in your xml.

This error is thrown when the parser reads an invalid tag at the start of the document. Normally where the prolog resides.

e.g.

  1. Root/><document>
  2. Root<document>

Solution 4

This error can come if there is validation error either in your wsdl or xsd file. For instance I too got the same issue while running wsdl2java to convert my wsdl file to generate the client. In one of my xsd it was defined as below

<xs:import schemaLocation="" namespace="http://MultiChoice.PaymentService/DataContracts" />

Where the schemaLocation was empty. By providing the proper data in schemaLocation resolved my problem.

<xs:import schemaLocation="multichoice.paymentservice.DataContracts.xsd" namespace="http://MultiChoice.PaymentService/DataContracts" />
Share:
212,076

Related videos on Youtube

Umesh Awasthi
Author by

Umesh Awasthi

Updated on April 20, 2020

Comments

  • Umesh Awasthi
    Umesh Awasthi about 4 years

    I am trying to call a web service but facing a strange behavior. we have a web-service running on my server but the code is not open to us so can not see what going on behind the wall The owner of the service have exposed web based test client UI which take input in a text box and will show the response to testing purpose.This input box is taking the input in the below mentioned format

    <CONTENT>
     <CONTENTID></CONTENTID>
     <DOCUMENTID>DRI2</DOCUMENTID>
     <LOCALECODE>en_US</LOCALECODE>
     <LATEST_VERSION>false</LATEST_VERSION>
     <INCREASEVIEWCOUNT>false</INCREASEVIEWCOUNT>
     <ACTIVITY_TYPE></ACTIVITY_TYPE>
    </CONTENT>
    

    its working fine on this UI but when i am trying to call this web service through my java code its getting connected as well getting authorized by the service but when i trying to call the above method it giving me the below error message

    AxisFault
     faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
     faultSubcode: 
     faultString: org.xml.sax.SAXParseException: Content is not allowed in prolog.
     faultActor: 
     faultNode: 
     faultDetail: 
     {http://xml.apache.org/axis/}stackTrace: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)
     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 javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
     at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
     at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
     at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
     at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
     at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
     at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
     at org.apache.axis.client.Call.invoke(Call.java:2767)
     at org.apache.axis.client.Call.invoke(Call.java:2443)
     at org.apache.axis.client.Call.invoke(Call.java:2366)
     at org.apache.axis.client.Call.invoke(Call.java:1812)
     at com.inquira.imwows.generated.ContentServicesSoapBindingStub.getContentRecord(ContentServicesSoapBindingStub.java:262)
     at com.inquira.prep.GetWebService.getcontentRecord(GetWebService.java:87)
     at com.inquira.prep.TestWs.main(TestWs.java:13)
    
     {http://xml.apache.org/axis/}hostname:umeshawasthi
    
    org.xml.sax.SAXParseException: Content is not allowed in prolog.
     at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
     at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:701)
     at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
     at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
     at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
     at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
     at org.apache.axis.client.Call.invoke(Call.java:2767)
     at org.apache.axis.client.Call.invoke(Call.java:2443)
     at org.apache.axis.client.Call.invoke(Call.java:2366)
     at org.apache.axis.client.Call.invoke(Call.java:1812)
     at com.inquira.imwows.generated.ContentServicesSoapBindingStub.getContentRecord(ContentServicesSoapBindingStub.java:262)
     at com.inquira.prep.GetWebService.getcontentRecord(GetWebService.java:87)
     at com.inquira.prep.TestWs.main(TestWs.java:13)
    Caused by: 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)
     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 javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
     at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
     at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
     ... 11 more
    

    below is the code for generating the required XML

    inputXml.append("<CONTENT>");
       inputXml.append("<CONTENTID>").append("</CONTENTID>");
       inputXml.append("<DOCUMENTID>").append("DRI2").append("</DOCUMENTID>");
       inputXml.append("<LOCALECODE>").append("en_US").append("</LOCALECODE>");
       inputXml.append("<LATEST_VERSION>").append("false").append("</LATEST_VERSION>");
       inputXml.append("<INCREASEVIEWCOUNT>").append("false").append("</INCREASEVIEWCOUNT>");
       inputXml.append("<ACTIVITY_TYPE>").append("</ACTIVITY_TYPE>");
       inputXml.append("</CONTENT>");
    

    and the generated XML is as below

    <CONTENT><CONTENTID></CONTENTID><DOCUMENTID>DRI2</DOCUMENTID><LOCALECODE>en_US</LOCALECODE><LATEST_VERSION>false</LATEST_VERSION><INCREASEVIEWCOUNT>false</INCREASEVIEWCOUNT><ACTIVITY_TYPE></ACTIVITY_TYPE></CONTENT>
    

    i even did timing of the generated string something as below

    inputXml.toString().trim().replaceFirst("^([\\W]+)<","<");
    

    but unable to find out whats going wrong,one thing i am sure there is some problem in the input XML as its working find on the test Page UI for the same XML

    any help in this regard is much appricated

    • weltraumpirat
      weltraumpirat over 13 years
      I get this kind of error message when saving XML files as UTF-8 with BOM. Where and how do you initialize the inputXML object?
    • jmj
      jmj over 13 years
      Try adding this at the top <?xml version="1.0" encoding="UTF-8"?>
    • Umesh Awasthi
      Umesh Awasthi over 13 years
      @Org.life.java: I also tried this thing nothing worked :(
    • Umesh Awasthi
      Umesh Awasthi over 13 years
      @Welteraumpirat:_content.getContentRecord(_token,test); this is the service method provided by them which takes 2 parameters both as string type
    • Raedwald
      Raedwald almost 10 years
  • Kevin Meredith
    Kevin Meredith over 10 years
    I checked whether this "BOM" existed by viewing my file in a Hex Editor. ef bb bf marked the first 3 bytes
  • Orkun Ozen
    Orkun Ozen about 10 years
    ok but isnT there a way to do this with SAX parser? Do we have to remove the BOM ourselves, before feeding the SAX (handler) ?
  • user2394284
    user2394284 over 7 years
    Isn't Prolog a programming language??? OK, I just so totally misunderstood that "Content is not allowed in Prolog" message!