小编Mar*_*K17的帖子

javax.xml.bind.UnmarshalException:意外元素(uri:“”,本地:“soap:信封”)

嗨,我已经使用 wsimport 从 WSDL 生成了 java 类。但是我已经将响应写入文件 *.xml。但是现在我想读取这个 xml 文件并填充已经生成的 java 类。

我试过了:

JAXBContext jc = JAXBContext.newInstance(Report.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
Report rc = (Report) unmarshaller.unmarshal(source);
Run Code Online (Sandbox Code Playgroud)

或者

JAXBContext jc = JAXBContext.newInstance(Report.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
Report rc = (Report) unmarshaller.unmarshal(new File("file.xml"));
Run Code Online (Sandbox Code Playgroud)

Report 是我发送请求时作为响应得到的类

在第一种情况下,我得到

javax.xml.bind.UnmarshalException: unexpected element (uri: "", local:"soap:Envelope") Expected elements are: (<{"http://pagewhereisthewsdl.com"}CLASSES>)+
Run Code Online (Sandbox Code Playgroud)

在第二种情况下

javax.xml.bind.UnmarshalException: unexpected element (uri: "http://schemas.xmlsoap.org/soap/envelope/", local:"Envelope") Expected elements are: (<{"http://pagewhereisthewsdl.com"}CLASSES>)+
Run Code Online (Sandbox Code Playgroud)

XML 是这样的:

<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>
Run Code Online (Sandbox Code Playgroud)

或者我能做什么?

java wsdl web-services jaxb

2
推荐指数
1
解决办法
6791
查看次数

标签 统计

java ×1

jaxb ×1

web-services ×1

wsdl ×1