我使用simpleXML解析从SOAP服务器返回的XML。
错误:
java.lang.RuntimeException: org.simpleframework.xml.core.ValueRequiredException:无法满足 @ org.simpleframework.xml.Element(data = false,name = identifier, 字段'id'上为required = true,类型= void)public java.lang.String be.test.model.response.ContentMetadataResponse $ Body.id 上课 be.test.app.core.service.model.response.ContentMetadataResponse $ Body 在第1行
响应:
<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getContentMetadataResponse xmlns:ns2="http://www.daisy.org/ns/daisy-online/" xmlns:ns3="http://purl.org/dc/elements/1.1/" xmlns:ns4="http://www.daisy.org/DRM/2005/KeyExchange" xmlns:ns5="http://www.w3.org/2000/09/xmldsig#" xmlns:ns6="http://www.w3.org/2001/04/xmlenc#" xmlns:ns7="http://www.daisy.org/z3986/2005/bookmark/">
<ns2:contentMetadata category="BOOK" requiresReturn="false">
<ns2:sample id="CA11957:sample"/>
<ns2:metadata>
<ns3:title>Game of thrones</ns3:title>
<ns3:identifier>CA11957</ns3:identifier>
<ns3:publisher>Royal National Institute for the Blind</ns3:publisher>
<ns3:format>Daisy 2.02</ns3:format>
<ns3:language>en</ns3:language>
<ns3:description>Del 1 i serien A song of ice and fire. Robert Baratheon blev kung efter att ha befriat de sju konungarikena från den galne draklorden, Aerys Targaryen. När kung Robert dör i en jaktolycka efterträds han av sin lille son. Men Eddard Stark misstänker att allt inte står rätt till. Intriger och maktkamp vid hovet leder till ett regelrätt krig mellan huset Stark och huset Lannister. Kampen om järntronen kan börja. Inläst på engelska</ns3:description>
<ns3:creator>Martin, George R R</ns3:creator>
<ns2:narrator>Carter, Tom</ns2:narrator>
<ns2:size>883774771</ns2:size>
<ns2:meta name="contentID" content="CA11957"/>
<ns2:meta name="cover" content="http://legimus.se/app/covers/max50x100/CA11957.png"/>
<ns2:meta name="includesAudio" content="true"/>
<ns2:meta name="publishedYear" content="2011"/>
<ns2:meta name="ISBN" content="9780007448036"/>
<ns2:meta name="targetGroup" content="Adults"/>
<ns2:meta name="language" content="en"/>
</ns2:metadata>
</ns2:contentMetadata>
</ns2:getContentMetadataResponse>
</S:Body>
</S:Envelope>
2019-04-15 09:35:39.048 20400-20435/com.mtm.android D/OkHttp: <-- END HTTP (1802-byte body)
代码:
@Root(name = "Envelope", strict = false)
public class ContentMetadataResponse {
@Path("Body/getContentMetadataResponse")
@Element(name = "contentMetadata")
public Body body;
@Root(strict = false)
public static class Body {
@Attribute(name = "category", required = false)
public String category;
@Attribute(name = "requiresReturn")
public boolean requiresReturn;
@Element(name = "sample", required = false)
public Identifier sample;
@Path("metadata")
@Element(name = "identifier")
public String id;
@Path("metadata")
@Element(name = "title")
public String title;
@Path("metadata")
@Element(name = "format")
public String format;
@Path("metadata")
@Element(name = "date", required = false)
public String date = "";
@Path("metadata")
@Element(name = "language", required = false)//XML might supply 0 or more tags, we only offer support for 1 here (can be changed to an inline ElementList if necessary)
public String language = "";
@Path("metadata")
@Element(name = "description", required = false)//See language
public String description = "";
@Path("metadata")
@Element(name = "creator", required = false)//See language
public String creator = "";
@Path("metadata")
@Element(name = "narrator", required = false)//See language
public String narrator = "";
@Path("metadata")
@Element(name = "size", required = false)
public long size;
@Path("metadata")
@ElementList(inline = true, entry = "meta")
private List<Pair> extras = new ArrayList<>();