什么是文本节点值的 Jaxb 等价物? [英] What is the Jaxb equivalent of a Text node value?

查看:19
本文介绍了什么是文本节点值的 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>

有谁知道在 value 成员变量上使用什么注释来实现这一点?到目前为止我得到的最接近的是:

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;
}

不幸的是,这种方法不允许我指定 value 成员变量不应呈现为它自己的标签 .

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天全站免登陆