org.xml.sax.SAXParseException: Content is not allowed in prolog

前端 未结 30 1828
别那么骄傲
别那么骄傲 2020-11-22 02:54

I have a Java based web service client connected to Java web service (implemented on the Axis1 framework).

I am getting following exception in my log file:

相关标签:
30条回答
  • 2020-11-22 03:49

    It means XML is malformed or the response body is not XML document at all.

    0 讨论(0)
  • 2020-11-22 03:49

    For me, a Build->Clean fixed everything!

    0 讨论(0)
  • 2020-11-22 03:49

    I was also getting the same

    XML reader error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,2] Message: Reference is not allowed in prolog.

    , when my application was creating a XML response for a RestFull Webservice call. While creating the XML format String I replaced the &lt and &gt with < and > then the error went off, and I was getting proper response. Not sure how it worked but it worked.

    sample:

    String body = "<ns:addNumbersResponse xmlns:ns=\"http://java.duke.org\"><ns:return>"
                +sum
                +"</ns:return></ns:addNumbersResponse>";
    
    0 讨论(0)
  • 2020-11-22 03:49

    Set your document to form like this:

    <?xml version="1.0" encoding="UTF-8" ?>
    <root>
        %children%
    </root>
    
    0 讨论(0)
  • 2020-11-22 03:50

    Just an additional thought on this one for the future. Getting this bug could be the case that one simply hits the delete key or some other key randomly when they have an XML window as the active display and are not paying attention. This has happened to me before with the struts.xml file in my web application. Clumsy elbows ...

    0 讨论(0)
  • 2020-11-22 03:53

    Just spent 4 hours tracking down a similar problem in a WSDL. Turns out the WSDL used an XSD which imports another namespace XSD. This imported XSD contained the following:

    <?xml version="1.0" encoding="UTF-8"?>
    <schema targetNamespace="http://www.xyz.com/Services/CommonTypes" elementFormDefault="qualified"
        xmlns="http://www.w3.org/2001/XMLSchema" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:CommonTypes="http://www.xyz.com/Services/CommonTypes">
    
     <include schemaLocation=""></include>  
        <complexType name="RequestType">
            <....
    

    Note the empty include element! This was the root of my woes. I guess this is a variation on Egor's file not found problem above.

    +1 to disappointing error reporting.

    0 讨论(0)
提交回复
热议问题