详细介绍URL: http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#deserialize
一、将JavaBean序列化为XML文件:
第一步:写一个Bean.
@Rootpublic class Example { @Element
private String text; @Attribute
private int index; public Example() { super(); }
public Example(String text, int index) { this.text = text; this.index = index; } public String getMessage() { return text; } public int getId() { return index; } }
第二步:关键代码。
Serializer serializer = new Persister(); Example example = new Example("Example message", 123); File result = new File("example.xml"); serializer.write(example, result);
第三步:出结果
<example index="123"> <text>Example message</text> </example>