我必须解析XML文件中的元素,可以是两种类型:的SimpleXML:用元素列表或文本
<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