在java中使用SAX解析器的问题

时间:2012-06-01 11:42:43

标签: java xml sax

使用SOAP请求调用Web服务时,将提供以下解析错误。 我检查了请求的序言,它没有空格或破折号。即使它会导致以下错误

org.xml.sax.SAXParseException: Content is not allowed in prolog.
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Un
  known 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.dispat
ch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Un
known 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 Sour
ce)
    at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:198)
    at requestModel.SimpleCheckMail.checkMail(SimpleCheckMail.java:162)
    at model.InboxDataBean.prepareList(InboxDataBean.java:97)
    at model.InboxDataBean.getemailList(InboxDataBean.java:207)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:87)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELR
esolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELRe
solver.java:203)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:1
89)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpress
ion.java:109)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.
 java:194)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.
java:182)
    at javax.faces.component.UIData.getValue(UIData.java:731)
    at javax.faces.component.UIData.getDataModel(UIData.java:1798)
    at javax.faces.component.UIData.setRowIndexWithoutRowStatePreserved(UIDa
ta.java:484)
    at javax.faces.component.UIData.setRowIndex(UIData.java:473)
    at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRen
 derer.java:81)
    at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.jav
 a:820)
    at javax.faces.component.UIData.encodeBegin(UIData.java:1118)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1754)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.
java:845)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1756)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView
(FaceletViewHandlingStrategy.java:401)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewH
andler.java:131)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePha
se.java:121)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:410)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:224)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
torBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
 ava:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
 927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp
 11Processor.java:987)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
AbstractProtocol.java:579)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoin
t.java:1805)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
utor.java:885)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:907)
    at java.lang.Thread.run(Thread.java:619)

请让我知道这个错误的问题......这个错误提前了吗


雅......你们所有人都是对的....但我得到的是,它是一个SOAP请求,我已经仔细地看到了请求,没有坏人.....但问题是是当我通过soap请求调用Web服务时,它将null作为一个respone,所以我得到错误..... 一旦Webservice正常工作......现在工作正常....感谢所有人

4 个答案:

答案 0 :(得分:1)

这意味着在<?xml ...仔细查看之前xml中存在某些内容。还要检查没有不可见的字符(您可以在任何HEX编辑器中执行此操作)。有时,Windows记事本会在文件开头添加标记。

答案 1 :(得分:0)

解析器在实际XML本身启动之前查看字符数据。要么确保XML在XML启动之前不包含任何内容,要么让SAX解析器忽略它......

答案 2 :(得分:0)

尝试显示您实际正在解析的数据。也许在你的xml开始之前插入了一些不好的字符,或者你可能没有读到正确的文件。

答案 3 :(得分:0)

如果你的XML文件存储为UTF-8(它可能是),这可能是因为BOM

Here,你有一个InputStream的例子,它摆脱了BOM。