Prolog SAXParserException 中不允许包含内容

我正在尝试调用Web服务,但面临奇怪的行为。我们有一个Web服务在我的服务器上运行,但代码没有对我们开放,所以看不到墙后面发生了什么服务的所有者已经公开了基于Web的测试客户端UI,该UI在文本框中输入,并将显示对测试目的的响应。此输入框采用以下提到的格式输入

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

它在这个UI上工作正常,但是当我试图通过我的java代码调用这个Web服务时,它也得到了服务的授权,但是当我尝试调用上述方法时,它会给我下面的错误消息

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

下面是用于生成所需 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>");

生成的 XML 如下所示

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

我甚至对生成的字符串进行了计时,如下所示

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

但无法找出出了什么问题,有一件事我确信输入XML中存在一些问题,因为它在测试页面UI上的工作发现相同的XML

这方面的任何帮助都得到了很多关注


答案 1

此错误可能与实际 XML 内容之前的字节顺序标记 (BOM) 有关。您需要解析返回的字符串并放弃 BOM,以便 SAXParser 可以正确处理文档。

您将在此处找到可能的解决方案。


答案 2

只需将其删除,请将xml文件粘贴到记事本中,您将在第一个标记之前看到额外的字符。删除它并粘贴回您的文件 - bof


推荐