I have this XML
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:listItemsResponse xmlns:ns2="http://soap.ws.server.wst.fit.cvut.cz/">
<return>
<code>OK</code>
<data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="ns2:items">
<item>
<itemId>1540041177</itemId>
<price>5109</price>
</item>
<item>
<itemId>696734629</itemId>
<price>5453</price>
</item>
<item>
<itemId>1853843391</itemId>
<price>5088</price>
</item>
</data>
</return>
</ns2:listItemsResponse>
</soap:Body>
</soap:Envelope>
and I want to unmarshall the data element to my POJO (not the whole XML, just the part of it). Is it possible with JAXB?
@XmlRootElement(name = "data")
public class Data {
private List<Item> items;
public Data() {
}
@XmlElement(name = "item")
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
@Override
public String toString() {
return "Data [" + (items != null ? "items=" + items : "") + "]";
}
}
You can use a StAX XMLStreamReader to advance to the content you are interested in and then unmarshal that.
For More Information
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With