我正在使用simpleframework来反序列化xml层次树。我发现simpleframework有TreeStrategy,但我找不到任何样本。你有什么例子吗?
我的XML示例:
<?xml version="1.0"?>
<SampleElem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Children>
<SampleElem>
<Children/>
<Id>1</Id>
<Value>Test2</Value>
</SampleElem>
</Children>
<Id>-1</Id>
<Value>Test1</Value>
</SampleElem>
谢谢!
答案 0 :(得分:0)
这会以某种方式帮助你吗?虽未经过测试;)
<强> XML:强>
<SampleElements name="example">
<children>
<SampleElement>
<id>1</id>
<value>Test1</value>
</SampleElement>
<SampleElement>
<id>-1</id>
<value>Test2</value>
</SampleElement>
</children>
</SampleElements>
Java集合对象:
@Root
public class SampleElements {
@ElementList
private List<SampleElement> children;
@Attribute
private String name;
public String getName() {
return name;
}
public List getProperties() {
return children;
}
}
@Root
public class SampleElement {
@Element
private int id;
@Element
private String value;
public int getId() {
return id;
}
public String getValue() {
return value;
}
}