Jaxb - 使用值对混合的 xml 元素进行 umarshaling [英] Jaxb - umarshaling mixed xml element with value

查看:10
本文介绍了Jaxb - 使用值对混合的 xml 元素进行 umarshaling的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 xml 元素:

I have the follwoing xml element:

<FIELD1><COMP VAR="A">text B</COMP> inner text <COMP VAR="B">text B</COMP></FIELD1>

如何使用 JAXB 注释此属性:

How to annotate this property with JAXB:

protected List<Object> compOrValue;

拥有 COMP xml 元素和字符串值的列表.

to have a list of COMP xml elemnts and String values.

JAXB 可以吗?

谢谢

推荐答案

您可以结合使用@XmlAnyElement 和@XmlMixed 来实现:

You can use a combination of @XmlAnyElement and @XmlMixed to achieve this:

import java.util.List;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlMixed;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="FIELD1")
public class Root {

    protected List<Object> compOrValue;

    @XmlAnyElement
    @XmlMixed
    public List<Object> getCompOrValue() {
        return compOrValue;
    }

    public void setCompOrValue(List<Object> compOrValue) {
        this.compOrValue = compOrValue;
    }

}

这篇关于Jaxb - 使用值对混合的 xml 元素进行 umarshaling的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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