【发布时间】:2016-12-06 22:55:52
【问题描述】:
我必须解析一个可以是两种类型的 XML 文件:
<property>
<value>Some text</value>
</property>
和
<property>
<value>
<item id="first_id"/>
<item id="second_id"/>
<item id="third_id"/>
</value>
</property>
如何用 Java 做到这一点?
我创建了一个类:
@Root(strict = false)
public class PropertyValue {
@ElementList(inline = true, required = false)
private List<ItemData> items;
@Text(required = false)
private String text;
}
ItemData 是 item 类。
但这不起作用。 代码给了我一个例外:
org.simpleframework.xml.core.TextException: Text annotation @org.simpleframework.xml.Text(data=false, empty=, required=false) on field 'text' private java.lang.String PropertyValue.text used with elements in class PropertyValue
【问题讨论】:
标签: java xml parsing xml-parsing simple-framework