0

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

谢谢!

4

1 回答 1

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;
   }
}
于 2013-05-07T22:33:29.740 回答