2016-12-27 8 views
0

私はアクセスしたいサービスを公開するUPnPデバイスを使っています。私はデータをマーシャリングするためにSimpleXMLを使用しています。これまでのところ、とても良いですが、今はもう固まっています。 以下のXMLを考えるとSimpleXMLが属性を逆シリアル化しないのはなぜですか?

<DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:dc="http://purl.org/dc/elements/1.1/"> 
    <item id="123456" parentID="1" restricted="1"> 
     <res protocolInfo="http-get:*:video/mpeg:*">http://stream_resource/media/index.m3u8</res> 
     <upnp:callSign>My Call Sign here</upnp:callSign> 
     <upnp:class>object.item.videoItem.videoBroadcast</upnp:class> 
     <dc:title>My Title Here</dc:title> 
    </item> 
</DIDL-Lite> 

私は、次ののPOJOあります

ルート:

@Root(name = "DIDL-Lite") 
@NamespaceList({ 
     @Namespace(reference = "urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"), 
     @Namespace(reference = "urn:schemas-upnp-org:metadata-1-0/upnp/", prefix = "upnp"), 
     @Namespace(reference = "http://purl.org/dc/elements/1.1/", prefix = "dc") 
}) 
public class ResultObject { 

    @ElementList(name = "item") 
    private List<ObjectItem> listItems; 
} 

ObjectItem:

@Root(name = "item") 
public class ObjectItem { 

    @Attribute(name = "id") 
    private String id; 

    @Attribute(name = "parentID") 
    private String parentID; 

    @Attribute(name = "restricted") 
    private String restricted; 

    @Element(name = "res")//something appears to be wrong here ! this element is not actually parsed ? 
    private ResourceInfo resInfo; 

    @Element(name = "callSign") 
    private String callSign; 

    @Element(name = "class") 
    private String upnpClass; 

    @Element(name = "title") 
    private String dcTitle; 
} 

たResourceInfo:

@Root(name = "res") 
public class ResourceInfo { 

    @Attribute(name = "protocolInfo") 
    private String protocolInfo; 
} 

これは私が取得パースエラー:System.errのは/ W:org.simpleframework.xml.core.AttributeException:属性 'protocolInfoは' クラスの試合を持っていません

ObjectItem:

xx.yyy.ObjectItemは掘り幾つか後

ライン1において、IはElementMapそう等にその値をデシリアライズしようとしました

まだ取得中です。解析エラーです。

ヒント

+0

あなたは、UPnP用のまとわりつきを使用していないのはなぜ? http://4thline.org/projects/cling/ –

+0

@PogonetsAnton私は抱きつけを統合しようとしましたが、2つの理由であきらめました:主に、私はUPNPでの作業経験が足りず、スタッキングとして私にとって重苦しいようでした。第二に、私が使用しているUPNPデバイスはカスタム検出と認証のメカニズムを使用していますが、私はそれを使用してデバイスとの接続を確立することはできませんでした。それを除いて、Clingはすばらしい図書館です。 – nightfixed

答えて

1

問題はObjectItemではなく、ObjectItemがResultObjectに格納される方法です。 List<ObjectItem> listItems;代わりの@ElementList(name = "item")

それとも@ElementList(inline = true)名に

使用@ElementList(name = "item", inline = true)が、この場合には必要ありません。

は、違いを参照してください:

@ElementList

@ElementList(inline = true)

+0

あなたが提案し解決したところで変更を加えました。さらに、私はすべての「@ ElementList」を「インライン化」しました。ありがとうございました ! – nightfixed

関連する問題