问题描述
我需要将 xml 文件转换为 java 对象。
<PRODUCT id="10" name="Notebook">
<VALUE id="30" type="Formatted">This is mixed <TUNIT style="style-12">formatted</TUNIT> text value.</VALUE>
</PRODUCT>
这是产品类:
@Getter
@Setter
@XmlRootElement(name = "PRODUCT")
@XmlAccessorType(XmlAccessType.FIELD)
public class Product {
@XmlAttribute(name = "id")
private String id;
@XmlAttribute(name = "name")
private String name;
@XmlElementRef(name = "VALUE")
private Value value;
}
这是值类:
@Getter
@Setter
@XmlRootElement(name = "VALUE")
@XmlAccessorType(XmlAccessType.FIELD)
public class Value {
@XmlAttribute(name = "id")
private String id;
@XmlAttribute(name = "type")
private String type;
@XmlValue
private String content;
@XmlElementRef(name = "TUNIT")
private Tunit tunit;
}
这是 Tunit 类:
@Getter
@Setter
@XmlRootElement(name = "TUNIT")
@XmlAccessorType(XmlAccessType.FIELD)
public class Tunit {
@XmlAttribute(name = "style")
private String style;
@XmlValue
private String content;
}
当我为 <VALUE>
属性 ID 设置 @XmlAttribute,为 <VALUE>
内容设置 @XmlValue,为 <TUNIT>
设置 @XmlElementRef 时 - 我收到一个错误:
If a class has @XmlElement property,it cannot have @XmlValue property.
是否可以使用 JAXB 解组此 xml?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)