嗨,我已经使用 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)
或者我能做什么?