I am trying to use the SimpleXML java library (by Niall Gallagher) to read an XML fragment whose content is text interspersed with 0 to n …. elements (the application I am working with supports a very minimalistic and filtered subset of HTML), i.e. for example:
...<value>text1<div>text2</div>text3<div>text4</div>text5</value>...
I am using the classes “Value” and “Div” like so:
package example;
public class Value {
@ElementList(entry="div", type=Div.class, inline=true, required=false)
private java.util.List<Div> divs;
@Text(required=false)
private String text;
// misc. utils (toString() etc.) omitted...
}
and
package example;
public class Div {
@Text(required=false)
private String text;
// misc. utils (toString() etc.) omitted...
}
But when I let this run the SiompleXML parser yields me an error:
...
Text annotation @org.simpleframework.xml.Text(data=false, empty=, required=false)
on field 'text' private transient java.lang.String example.Value.text
used with elements in class example.Value org.simpleframework.xml.core.TextException:
Text annotation @org.simpleframework.xml.Text(data=false, empty=, required=false)
on field 'text' private transient java.lang.String example.Value.text
used with elements in class example.Value
at org.simpleframework.xml.core.TreeModel.validateText(TreeModel.java:376)
at org.simpleframework.xml.core.TreeModel.validate(TreeModel.java:362)
...
(note: the linebreaks are mine – the entire eror message is on a single line)
I simply can’t make sense of that error message. Any idea what’s not correct here or what I am missing?