2016-04-22 74 views
-1

我想创建XML字符串像下面和我使用Simple Xml标签与元素(无标签)和Android的属性使用简单的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>。我该如何处理?

+1

能否请您为-1解释? – KDeogharkar

回答

1

使用@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> 
+0

ohk我会检查。 – KDeogharkar

+0

感谢的人。有用 – KDeogharkar