如何在simpleframework中使用TreeStrategy



我使用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>

谢谢!

这对你有帮助吗?未测试;)

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

最新更新