Java JAXB xml pojo类 [英] Java JAXB xml pojo classes

查看:105
本文介绍了Java JAXB xml pojo类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用具有这种xml结构的JAXB创建POJO类:

How can I create the POJO classes with JAXB with such a xml structure :

<principale>
   <procedure>
      <procedure>
         <param1>value1</param1>
         <param2>value2</param2>
      </procedure>
      <procedure>
         <param1>value3</param1>
         <param2>value4</param2>
      </procedure>
   </procedure>
</principale>

如您所见,第一个过程标签不是根标签,与第二个过程相同标记。

As you can see the first procedure tag is not the root one and is the same than the second procedure tag.

推荐答案

如果外部过程元素不可重复,请尝试它与 @ XmlElementWrapper

If the outer procedure element is not repeatable, try it with @XmlElementWrapper:

@XmlRootElement(name="principale")
public class Principale {
    @XmlElementWrapper(name="procedure")
    @XmlElement(name="procedure")
    public List<Params> procedures = new LinkedList<Params>();
}
public class Params {
   @XmlElement(name="param")
   public List<String> params = new LinkedList<String>();
}

(未经测试。)

这篇关于Java JAXB xml pojo类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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