2017-01-15 7 views
1

Retrofitに添付されているSimpleXMLを使用しています。私はcallSignを解析したくないAndroid - 要素を無視する単純なフレームワークパーサーですか?

<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> 

しかし、:私のXML項目は、次のようになります。私は意図的に私のPOJOからこのOMMIT 場合、私は例外を取得:

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; 
} 

は、私は自分の質問にお答えします、

答えて

1

、ありがとうございました。

1):http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#loosemap

への言及は、私は2つの変更を行いました。すべて@Rootの要素にはstrict = falseを指定する必要があります。

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

2)。 Retrofit instanceコンバータファクトリが作成されましたnonStrict

.addConverterFactory(SimpleXmlConverterFactory.createNonStrict()) 
関連する問題