qq_23039605
小与哥
2018-01-02 11:28

jaxb 实现 soap.xml 转 java bean

5
  • java
  • bean

xml 具体示例如下:

 <?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <PostBikeInfoResponse xmlns="http://tempuri.org/">
      <PostBikeInfoResult>
        <Code>int</Code>
        <Message>string</Message>
      </PostBikeInfoResult>
    </PostBikeInfoResponse>
  </soap:Body>
</soap:Envelope>

对应的 java bean类,我是这样编写的:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name="soap:Envelope")
public class ResponseEntity {

@XmlAttribute(name="xmlns:xsi")
private String xsi;
@XmlAttribute(name="xmlns:xsd")
private String xsd;
@XmlAttribute(name="xmlns:soap")
private String soap;
@XmlElement(name="soap:Body")
private ResponseBody ResponseBody;
......

问题:

 javax.xml.bind.UnmarshalException: 意外的元素 (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Envelope")。所需元素为<{http://tempuri.org/}PostBikeInfoResponse>,<{}PostBikeInfoResult>,<{}soap:Body>,<{}soap:Envelope>

具体错误的原因是什么?

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答

为你推荐