什么是JAXB相当于一个文本节点值吗? [英] What is the Jaxb equivalent of a Text node value?

查看:491
本文介绍了什么是JAXB相当于一个文本节点值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待转换成一类,看起来像这样...

I am looking to convert a class that looks like this ...

public class Amenity {
   public String id;
   public String value;
}

到使用JAXB注释以下XML:

into the following XML using JaxB annotations:

<amenity id="id-string-here">value-string-here</amenity>

有谁知道在价值用什么注解成员变量做到这一点?到目前为止,我已经得到最接近的是:

Does anyone know what annotation to use on the value member variable to accomplish this? The closest I've gotten so far is:

@XmlRootElement
public class Amenity {
   @XmlAttribute
   public String id;
   @XmlElement
   public String value;
}

不幸的是这种方法不容许我指定的成员变量不应该呈现为自己的标记&LT;价值&GT;&LT ; /值方式&gt;

Unfortunately this approach doesn't allow me to specify that the value member variable should not be rendered as its own tag <value></value>.

推荐答案

我不是100%肯定这一点,但尝试使用 @XmlValue 注释,而不是 @XmlElement

I'm not 100% sure about this, but try to use an @XmlValue annotation instead of @XmlElement.

这篇关于什么是JAXB相当于一个文本节点值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆