2016-01-19 38 views
0

我想解析一個XML的改造,但我卡在ElementList中。Simplexmlconverter,元素和屬性的元素列表

我的XML看起來是這樣的:

<OBJECT> 
    <LIST> 
     <ITEM attribute="20160119">tue</ITEM> 
     <ITEM attribute="20160118">wed</ITEM> 
     <ITEM attribute="20160117">thu</ITEM> 
    </LIST> 
    <OTHER>some text</OTHER> 
</OBJECT> 

我的模式是這樣的:

@Root (name = "OBJECT", strict = false) 
class Object { 

    @Element (name = "OTHER", required = false) 
    String other; 
    @Element (name = "LIST", required = false) 
    List list; 

    //Constructor and getters 

} 

@Root (name = "LIST", strict = false) 
class LIST { 

    @ElementList (name = "ITEM", inline = true, required = false) 
    private ArrayList<Item> items; 

    //Constructor and getters 

} 

@Root (name = "ITEM", strict = false) 
class Item { 

    @Attribute (name = "attribute", required = false) 
    String attribute; 
    @Element (required = false) 
    String value; 

    //Constructor and getters 

} 

項目列表對象有正確的屬性是空值。

任何想法? 謝謝。

回答

1

我解決改變

@Element(所需=假) 字符串值;

@Text(所需=假) 字符串值;

希望這可能對某人有用。