tags:

views:

413

answers:

3

I need to parse xml data from string bufer or string ..i do code as follows. here on the line document doc =db.parse(eventXml ) ..it throws exception-- plesae find below code and exception .plese help me

Code ---

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

Document doc = db.parse(eventXml );

exception---

java.net.MalformedURLException: no protocol: <?xml version="1.0" encoding="UTF-8
" standalone="yes"?>%0A<EventInfo xmlns="http://www.telenet.be/oms/event"&gt;%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)
>
.
+2  A: 

You are invoking

Document doc = db.parse(eventXml);

with eventXml apparently being a string of XML data.

However, the method DocumentBuilder.parse(String) expects a URI to load the XML from. That's why you get a MalformedURLException: Java tries to use your XML as an URI.

You want DocumentBuilder.parse(InputSource), or DocumentBuilder.parse(InputStream). The InputStream can be created from your String/StringBuffer using e.g.

new InputSource(new StringReader(xmlString))

(untested).

sleske
+3  A: 

parse() doesn't take actual XML as a parameter, instead it takes URL to a document.

You should use DocumentBuilder.parse(new StringBufferInputStream(eventXml));

alamar
(+1) .. as clearly written in the JavaDoc for DocumentBuilder#parse. If still in doubt, google for 'DocumentBuilder' and follow the first link.
Andreas_D
+1  A: 

You have posted so much content but nothing that can help any reader to see what you were trying to do. If your problem is just that XML parsing is giving you a problem then check that your XML is well-formed.

Khangharoth