我需要解组XML。
XML就像这样:
<array>
<item>
<name>nick</pid>
<age>18</provider>
</item>
<item>
<name>gogo</pid>
<age>20</provider>
</item>
</array>
好的,这很好。现在我的java类是这样的:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "array")
public class Root{
@XmlElement(name = "item", type = Provider.class)
private List<Item> array = new ArrayList<Item>();
...
}
然后:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "item")
public class Item{
private Integer age;
private String name;
...
现在一切都很好!解组很顺利!
但如果我有这样的SOAP响应,我该怎么办?
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns="http://example.com/ns.xsd" xmlns:impl="http://example.com/impl.xsd">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns:ProviderResponse>
<Status>OK</Status>
<array>
...
<item>
...
</item>
...
</array>
</ns:ProviderResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
如何跳过SOAP-ENV:Envelope,SOAP-ENV:Header,SOAP-ENV:Body,ns:ProviderResponse标签? 现在,有了这个XML,当我试图解组时我有这样的错误:
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Envelope"). Expected elements are <{}array>,<{}item>
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:647)