如何将XML解组到Java对象

时间:2019-06-01 07:10:17

标签: soap jaxb unmarshalling

这是我的XML IAM试图将其编组为Java对象。 我正在使用肥皂信封将Java对象编组为xml

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:namesp2="http://xml.apache.org/xml-soap"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
<SOAP-ENV:Body>
<namesp1:searchResponse
xmlns:namesp1="WebServices">
<SOAP-ENC:Array xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="namesp2:SOAPStruct[5]">
<item xsi:type="namesp2:SOAPStruct">
<id xsi:type="xsd:int">2</mrid>
</item>
<item xsi:type="namesp2:SOAPStruct">
<id xsi:type="xsd:int">6</mrid>
</item>
<item xsi:type="namesp2:SOAPStruct">
<id xsi:type="xsd:int">7</mrid>
</item>
</SOAP-ENC:Array>
</namesp1:searchResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

这些或我的pojo课

@XmlRootElement(name = "searchResponse", namespace = "WebServices")
public class SearchResponce {

public SearchResponce() {
}

public SearchArray getSearchArray() {
return searchArray;
}
@XmlElement(name = "Array")
public void setSearchArray(SearchArray searchArray) {
this.searchArray = searchArray;
}

private SearchArray searchArray;
}

public class SearchArray {
public SearchArray() {
}

@Override
public String toString() {
return "SearchResponce{" +
"item=" + item +
'}';
}

private List<Item> item;




public List<Item> getItem() {
return item;
}
@XmlElement(name = "item")
public void setItem(List<Item> item) {
this.item = item;
}
}

public class Item
{

private Integer Id;

@Override
public String toString() {
return "Item{" +
"Id=" + Id +
'}';
}

public Item() {
}

public Integer getId() {
return Id;
}
@XmlElement(name = "id")
public void setId(Integer Id) {
this.mrId = Id;
}
}

SearchResponce searchResponseCase =(SearchResponce)unmarshaller.unmarshal(reply.getSOAPBody()。extractContentAsDocument());

我遇到错误 无法从身体提取文件。可以请你帮我吗。

0 个答案:

没有答案