java - javax.xml.bind.UnmarshalException: unexpected element (uri: "", local:"soap:Envelope") -


hi have generated java classes wsdl using wsimport.but have written response file *.xml. want read xml file , populate java classes have been generated.

i have tried:

jaxbcontext jc = jaxbcontext.newinstance(report.class); unmarshaller unmarshaller = jc.createunmarshaller(); report rc = (report) unmarshaller.unmarshal(source); 

or

jaxbcontext jc = jaxbcontext.newinstance(report.class); unmarshaller unmarshaller = jc.createunmarshaller(); report rc = (report) unmarshaller.unmarshal(new file("file.xml")); 

report class response when send request

in first case get

javax.xml.bind.unmarshalexception: unexpected element (uri: "", local:"soap:envelope") expected elements are: (<{"http://pagewhereisthewsdl.com"}classes>)+ 

in second case

javax.xml.bind.unmarshalexception: unexpected element (uri: "http://schemas.xmlsoap.org/soap/envelope/", local:"envelope") expected elements are: (<{"http://pagewhereisthewsdl.com"}classes>)+ 

xml this:

<soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">       <soap:body>               <ns3:getreportonlineresponse xmlns:ns2="http://pagewhereisthewsdl.com/document" xmlns:ns3="http://pagewhereisthewsdl.com/endpoint">                  <ns2:report>                        ...                  </ns2:report>            </ns3:getreporteonlineresponse>        </soap:body> </soap:envelope> 

or can ?

i believe you're not taking soap envelope account. need extract body's content first.

string xml = "<insert xml>"; soapmessage message = messagefactory.newinstance().createmessage(null, new bytearrayinputstream(xml.getbytes())); jaxbcontext jc = jaxbcontext.newinstance(report.class); unmarshaller unmarshaller = jc.createunmarshaller(); report rc = (report) unmarshaller.unmarshal(message.getsoapbody().extractcontentasdocument()); 

Comments