我的问题是:来自 xml
方案:
<topnode>
topNodeValue
<bottomnode/>
</topnode>
用 Jaxb 生成的类看起来像
class topnode {
List<bottomnode> bottomnodeList;
}
它不会生成值字段来设置顶级节点的值。
我怎样才能做到这一点?谢谢。
最佳答案
当一个元素的内容同时包含字符和元素数据时,它被称为混合内容。在 JAXB (JSR-222)这是使用 @XmlMixed
注释映射的,例如:
class topnode {
@XmlMixed
String text;
List<bottomnode> bottomnodeList;
}
混合内容的使用可能会很棘手,因为您可能会因为用于格式化的文本节点而获得意想不到的结果。有关更详细的解释,请参阅以下对类似问题的回答。
关于jaxb - 我如何设置 Jaxb XMLelement 的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12194728/