gpt4 book ai didi

Android - 忽略元素的简单框架解析器?

转载 作者:行者123 更新时间:2023-11-29 01:13:06 28 4
gpt4 key购买 nike

我正在使用附加到 RetrofitSimpleXML。我的 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).指定所有应具有 strict = false@Root 元素。

@Root(name = "item", strict = false)

2). Retrofit 实例 转换器工厂已创建 nonStrict:

.addConverterFactory(SimpleXmlConverterFactory.createNonStrict())

关于Android - 忽略元素的简单框架解析器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41664188/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com