异常:读取 XML 时没有协议

2022-09-04 04:58:40

我需要从字符串 bufer 或字符串中解析 xml 数据。我做代码如下。在这里行..它抛出异常 - plesae在下面找到代码和异常.plese帮助我document doc =db.parse(eventXml )

法典

eventXml = strBuffer.toString();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();

Document doc = db.parse(eventXml );

例外

 java.net.MalformedURLException: no protocol: <?xml version="1.0" encoding="UTF-8
    " standalone="yes"?>%0A<EventInfo xmlns="http://www.telenet.be/oms/event">%0A
     <TelenetEventInfo className="be.telenet.oms.events.OmsAsapJsrpNotifyEvent">%0A
           <SimpleFields>%0A            <SimpleField>%0A                <FieldName>C
    ompletion_Date_Time</FieldName>%0A                <FieldValue>04/08/2009 08:34:0
    1</FieldValue>%0A            </SimpleField>%0A            <SimpleField>%0A
              <FieldName>Originator</FieldName>%0A                <FieldValue>System
    </FieldValue>%0A            </SimpleField>%0A            <SimpleField>%0A
             <FieldName>Status</FieldName>%0A                <FieldValue>S</FieldVal
    ue>%0A            </SimpleField>%0A            <SimpleField>%0A                <
    FieldName>Workorder_ID</FieldName>%0A                <FieldValue>I00054132231-09
    8</FieldValue>%0A            </SimpleField>%0A        </SimpleFields>%0A
    <ArrayData>%0A            <ArrayNames>%0A                <ArrayName>Parameters</
    ArrayName>%0A                <ArrayFieldEntry>%0A                    <ArraySubFi
    eld>[0].Parameter_Name</ArraySubField>%0A                    <ArraySubFieldValue
    >WARNING_TEXT</ArraySubFieldValue>%0A                </ArrayFieldEntry>%0A
              <ArrayFieldEntry>%0A                    <ArraySubField>[0].Parameter_v
    alue</ArraySubField>%0A                    <ArraySubFieldValue>UnknownKeyExcepti
    on-Retrieving a webURL%0A                    for an unknown loginid: a004301</Ar
    raySubFieldValue>%0A                </ArrayFieldEntry>%0A                <ArrayF
    ieldEntry>%0A                    <ArraySubField>[1].Parameter_Name</ArraySubFiel
    d>%0A                    <ArraySubFieldValue>AGED</ArraySubFieldValue>%0A
             </ArrayFieldEntry>%0A                <ArrayFieldEntry>%0A
          <ArraySubField>[1].Parameter_value</ArraySubField>%0A                    <
    ArraySubFieldValue/>%0A                </ArrayFieldEntry>%0A                <Arr
    ayFieldEntry>%0A                    <ArraySubField>[2].Parameter_Name</ArraySubF
    ield>%0A                    <ArraySubFieldValue>OPERATION</ArraySubFieldValue>%0
    A                </ArrayFieldEntry>%0A                <ArrayFieldEntry>%0A
                  <ArraySubField>[2].Parameter_value</ArraySubField>%0A
           <ArraySubFieldValue>DEL</ArraySubFieldValue>%0A                </ArrayFie
    ldEntry>%0A                <ArrayFieldEntry>%0A                    <ArraySubFiel
    d>[3].Parameter_Name</ArraySubField>%0A                    <ArraySubFieldValue>S
    USPEND</ArraySubFieldValue>%0A                </ArrayFieldEntry>%0A
       <ArrayFieldEntry>%0A                    <ArraySubField>[3].Parameter_value</A
    rraySubField>%0A                    <ArraySubFieldValue/>%0A                </Ar
    rayFieldEntry>%0A            </ArrayNames>%0A        </ArrayData>%0A        <eve
    ntName>OMS::ASAP::JSRP::Notify</eventName>%0A        <destination>OSB</destinati
    on>%0A    </TelenetEventInfo>%0A</EventInfo>%0A%0A
            at java.net.URL.<init>(URL.java:537)
            at java.net.URL.<init>(URL.java:434)
            at java.net.URL.<init>(URL.java:383)
            at weblogic.apache.xerces.impl.XMLEntityManager.startEntity(XMLEntityMan
    ager.java:836)
            at weblogic.apache.xerces.impl.XMLEntityManager.startDocumentEntity(XMLE
    ntityManager.java:782)
            at weblogic.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(XML
    DocumentScannerImpl.java:260)
            at weblogic.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguratio
    n.java:499)
            at weblogic.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguratio
    n.java:581)
            at weblogic.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)
            at weblogic.apache.xerces.parsers.DOMParser.parse(DOMParser.java:257)
            at weblogic.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilder
    Impl.java:201)
            at weblogic.xml.jaxp.RegistryDocumentBuilder.parse(RegistryDocumentBuild
    er.java:149)
            at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124)
            at Controller.getEvent_Xml(Controller.jpf:822)
            at Controller.GetDetails(Controller.jpf:487)
            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:324)
            at com.bea.wlw.netui.pageflow.FlowController.invokeActionMethod(FlowCont
    roller.java:1512)
            at com.bea.wlw.netui.pageflow.FlowController.getActionMethodForward(Flow
    Controller.java:1447)
            at com.bea.wlw.netui.pageflow.FlowController.internalExecute(FlowControl
    ler.java:778)
            at com.bea.wlw.netui.pageflow.PageFlowController.internalExecute(PageFlo
    wController.java:211)
            at com.bea.wlw.netui.pageflow.FlowController.execute(FlowController.java
    :608)
            at org.apache.struts.action.RequestProcessor.processActionPerform(Reques
    tProcessor.java:484)
            at com.bea.wlw.netui.pageflow.PageFlowRequestProcessor.processActionPerf
    orm(PageFlowRequestProcessor.java:1504)
            at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja
    va:274)
            at com.bea.wlw.netui.pageflow.PageFlowRequestProcessor.process(PageFlowR
    equestProcessor.java:674)
            at com.bea.wlw.netui.pageflow.AutoRegisterActionServlet.process(AutoRegi
    sterActionServlet.java:527)
            at com.bea.wlw.netui.pageflow.PageFlowActionServlet.process(PageFlowActi
    onServlet.java:152)
            at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)

            at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
            at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
    (ServletStubImpl.java:1072)
            at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
    pl.java:465)
            at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
    pl.java:348)
            at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
    n.run(WebAppServletContext.java:6985)
            at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticate
    dSubject.java:321)
            at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:
    121)
            at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
    rvletContext.java:3892)
            at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
    pl.java:2766)
            at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
            at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
      Closing down all connections...

    <Jun 8, 2009 4:03:18 PM IST> <Error> <HTTP> <BEA-101019> <[ServletContext(id=312
    55131,name=ECToolWeb,context-path=/ECToolWeb)] Servlet failed with IOException
    java.net.SocketTimeoutException: Read timed out
            at java.net.SocketInputStream.socketRead0(Native Method)
            at java.net.SocketInputStream.read(SocketInputStream.java:129)
            at weblogic.servlet.internal.PostInputStream.read(PostInputStream.java:1
    70)
            at weblogic.servlet.internal.ServletInputStreamImpl.read(ServletInputStr
    eamImpl.java:180)
            at weblogic.servlet.internal.ServletRequestImpl.mergePostParams(ServletR
    equestImpl.java:1339)
            at weblogic.servlet.internal.ServletRequestImpl.parseQueryParams(Servlet
    RequestImpl.java:1206)
            at weblogic.servlet.internal.ServletRequestImpl.getParameter(ServletRequ
    estImpl.java:1409)
            at weblogic.servlet.internal.ServletRequestImpl.getParameter(ServletRequ
    estImpl.java:1395)
            at com.bea.wlw.netui.pageflow.scoping.ScopedServletUtils.getScopedSessio
    nAttrName(ScopedServletUtils.java:301)
            at com.bea.wlw.netui.pageflow.PageFlowUtils.getCurrentActionResolver(Pag
    eFlowUtils.java:496)
            at com.bea.wlw.netui.pageflow.PageFlowUtils.getCurrentPageFlow(PageFlowU
    tils.java:478)
            at com.bea.wlw.netui.pageflow.PageFlowUtils.ensureCurrentPageFlow(PageFl
    owUtils.java:454)
            at com.bea.wlw.netui.pageflow.PageFlowJspFilter.doFilter(PageFlowJspFilt
    er.java:193)
            at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.ja
    va:27)
            at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
    n.run(WebAppServletContext.java:6987)
            at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticate
    dSubject.java:321)
            at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:
    121)
            at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
    rvletContext.java:3892)
            at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
    pl.java:2766)
            at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
            at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
    --------------- nested within: ------------------
    weblogic.utils.NestedRuntimeException: Cannot parse POST parameters of request:
    '/ECToolWeb/DetailDisplay.jsp' - with nested exception:
    [java.net.SocketTimeoutException: Read timed out]
            at weblogic.servlet.internal.ServletRequestImpl.mergePostParams(ServletR
    equestImpl.java:1364)
            at weblogic.servlet.internal.ServletRequestImpl.parseQueryParams(Servlet
    RequestImpl.java:1206)
            at weblogic.servlet.internal.ServletRequestImpl.getParameter(ServletRequ
    estImpl.java:1409)
            at weblogic.servlet.internal.ServletRequestImpl.getParameter(ServletRequ
    estImpl.java:1395)
            at com.bea.wlw.netui.pageflow.scoping.ScopedServletUtils.getScopedSessio
    nAttrName(ScopedServletUtils.java:301)
            at com.bea.wlw.netui.pageflow.PageFlowUtils.getCurrentActionResolver(Pag
    eFlowUtils.java:496)
            at com.bea.wlw.netui.pageflow.PageFlowUtils.getCurrentPageFlow(PageFlowU
    tils.java:478)
            at com.bea.wlw.netui.pageflow.PageFlowUtils.ensureCurrentPageFlow(PageFl
    owUtils.java:454)
            at com.bea.wlw.netui.pageflow.PageFlowJspFilter.doFilter(PageFlowJspFilt
    er.java:193)
            at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.ja
    va:27)
            at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
    n.run(WebAppServletContext.java:6987)
            at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticate
    dSubject.java:321)
            at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:
    121)
            at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
    rvletContext.java:3892)
            at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
    pl.java:2766)
            at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
            at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
    >
.

答案 1

您正在调用

Document doc = db.parse(eventXml);

eventXml显然是一串XML数据。

但是,方法 DocumentBuilder.parse(String) 期望从中加载 XML 的 URI。这就是为什么你得到一个格式错误的URLException:Java试图使用你的XML作为URI。

你需要 DocumentBuilder.parse(InputSource) 或 DocumentBuilder.parse(InputStream)。InputStream可以从您的String/StringBuffer创建,例如

new InputSource(new StringReader(xmlString))

(未经测试)。


答案 2

parse()不采用实际的 XML 作为参数,而是采用文档的 URL。

您应该使用
DocumentBuilder.parse(new StringBufferInputStream(eventXml));


推荐