例外:读取XML时没有协议

时间:2009-06-08 10:48:36

标签: java xml

我需要从字符串缓冲区或字符串中解析xml数据..i代码如下。 这里就行document doc =db.parse(eventXml ) ..引发异常 - plesae找到下面的代码和异常。请帮助我

代码

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)
    >
.

5 个答案:

答案 0 :(得分:30)

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

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

答案 1 :(得分:25)

您正在调用

Document doc = db.parse(eventXml);

eventXml显然是一串XML数据。

但是,方法DocumentBuilder.parse(String)需要一个URI来加载 XML。这就是你得到MalformedURLException的原因:Java试图将你的XML用作URI。

您需要DocumentBuilder.parse(InputSource)或DocumentBuilder.parse(InputStream)。可以使用例如

从String / StringBuffer创建InputStream
new InputSource(new StringReader(xmlString))

(未测试的)。

答案 2 :(得分:8)

而不是db.parse(eventXml),请尝试:

Document doc = db.parse(new InputSource(new StringReader(eventXml)));

答案 3 :(得分:1)

您发布了如此多的内容,但没有任何内容可以帮助任何读者了解您的目标。 如果你的问题只是XML解析给你一个问题,那么检查你的XML是否格式正确。

答案 4 :(得分:0)

此代码段应该有效。

private String updateMyXML(String orderXML) {
    javax.xml.parsers.DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    InputSource inputSource = new InputSource(new StringReader(orderXML));
}