我正在使用连接到SimpleXML
的Retrofit
。我的XML项目如下所示:
<item id="1-22-33-55" parentID="1" restricted="1">
<res protocolInfo="http-get:*:video/mpeg:*">http://<blablahere>/slash/slash</res>
<upnp:callSign>Channel</upnp:callSign>
<upnp:channelID type="ANALOG">1</upnp:channelID>
<upnp:channelID type="DIGITAL">1,0</upnp:channelID>
<upnp:channelID type="SI">1,1019,10301</upnp:channelID>
<upnp:channelID type="UNIVERSAL">578865282</upnp:channelID>
<upnp:class>object.item.videoItem.videoBroadcast</upnp:class>
<dc:title>Channel</dc:title>
</item>
但是,我不想解析
callSign
。如果我有意从POJO中忽略了这一点,则会出现异常:org.simpleframework.xml.core.ElementException: Element 'callSign' does not have a match in class xxxxx.yyyyy.zzzzz.ContentDirectoryChannelItem at line 1
有没有一种方法可以指定在解析时专门忽略哪个元素?
我的POJO:
public class ContentDirectoryChannelItem {
@Attribute(name = "id")
private String chanId;
@Attribute(name = "parentID")
private String parentID;
@Attribute(name = "restricted")
private String restricted;
@ElementMap(entry = "channelID", key = "type", attribute = true, inline = true)
private Map<String, String> channelIDmap;
@Element(name = "class")// I want this out also !!!
private String upnpClass;
@Element(name = "title")
private String dcTitle;
@ElementMap(entry = "res", key = "protocolInfo", attribute = true, inline = true)
private Map<String, String> resourceMap;
}
谢谢,
最佳答案
我会回答我自己的问题。引用http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#loosemap
我做了2处更改:
1)。指定应具有@Root
的所有strict = false
元素。
@Root(name = "item", strict = false)
2)。
Retrofit instance
转换器工厂已创建nonStrict
:.addConverterFactory(SimpleXmlConverterFactory.createNonStrict())