我想创建xml字符串,如下所示,我正在使用Simple Xml
<data name = "your name">please enter your name</data>
为此我正在创建类
@Root(name = "data")
public class Data {
@Attribute(name = "name")
private String x;
private String value;
public String getX() {
return x;
}
public void setX(String x) {
this.x = x;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
但它在序列化之后给我字符串,如::
<data name = "your name"/>
如果我将@Element注释设置为值
@Element
private String value;
然后它带有我不想要的价值标签
<data name = "your name"><value>please enter your name</value></data>
那么如何在对象上面映射字符串呢?
如果我有<font color = "red">this is text</font>
怎么办?我怎么处理呢?
答案 0 :(得分:2)
使用@Text属性。
示例:
@Root
public class Entry {
@Attribute
private String name;
@Attribute
private int version;
@Text
private String value;
public int getVersion() {
return version;
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
}
输出:
<entry version='1' name='name'>
Some example text within an element
</entry>