我有这个类确定指标:如何使用JAXB批注从Java类重命名XML属性?
@XmlRootElement
public class RssRoot {
private String _version;
private String _xmlns_content;
@XmlAttribute()
public String get_version() {
return _version;
}
@XmlAttribute()
public String get_xmlns_content() {
return _xmlns_content;
}
public void set_version(String version) {
_version = version;
}
public void set_xmlns_content(String xmlnsContent) {
_xmlns_content = xmlnsContent;
}
public RssRoot() {
super();
this._version = "2.0";
this._xmlns_content = "http://purl.org/rss/1.0/modules/content/";
}
}
而且它生成此XML:
<rssRoot xmlnsContent="http://purl.org/rss/1.0/modules/content/" version="2.0"/>
不过,我需要重新命名xmlnsContent
到xmlns:content
,并rssRoot
,以rss
。我怎样才能做到这一点?
我尝试了@XmlAttribute(name = "xmlns:content")
以上的getter和附近的属性声明,但没有运气。事情失败,此消息:
根异常堆栈跟踪: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:1个计数IllegalAnno的 tationExceptions 类具有相同名称的两个属性“_xmlns_content “ 此问题与以下位置有关:RssRoot
我还能做什么?