如何处理使用Jaxb解析的xml文件而不是根元素

时间:2017-05-07 14:57:11

标签: java xml parsing jaxb

有人可以在下一个情况下给我一个建议: 我的xml文件中有这样的结构:

    <?xml ... ?>
    <root>
     <listof_aaa>
      <aaa>aaa_object</aaa>
      <aaa>aaa_object</aaa>
      ...
     </listof_aaa>
     <listof_bbb>
      <bbb>bbb_object</bbb>
      <bbb>bbb_object</bbb>
      ...
     </listof_bbb>
     <listof_ccc>
      <ccc>ccc_object</ccc>
      <ccc>ccc_object</ccc>
      ...
     </listof_ccc>
   </root>

我的目标是首先阅读所有aaa对象,然后阅读bbb等等...... 我如何解析这样的结构,如果在根标签中我有几个不同的对象族?我想过使用JAXB,但是无法理解,在这种情况下我能用它做多好。

P.S。所有对象系列都是POJO。 谢谢!

1 个答案:

答案 0 :(得分:0)

您的案例中的典型自动生成类如下所示:

MATCH (u:User)-[:OWN]->(p:Product)
WITH u, COUNT(p.value) as count // calc de count for every user
WITH MAX(count) as max // save the 'max' value from 'count' (16, in your case)
MATCH (u:User)-[:OWN]->(p:Product)
WITH u, COUNT(p.value) as count, max
WHERE count = max // pass by WITH only when 'count' is equals 16
RETURN u.value as user, count

迭代:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "listof_aaa",
    "listof_bbb",
    "listof_ccc",
    "listinside"
})
@XmlRootElement(name = "root")
public class Root {

    @XmlElement(required = true)
    protected Listof_aaa listof_aaa;
    protected Listof_bbb listof_bbb;
    protected Listof_ccc listof_ccc;
    protected java.util.List<Listinside> listinside // example of multiple elements with one node name under the root

    public Listof_aaa getListof_aaa() {
      return listof_aaa;
    }

    public void setListof_aaa(Listof_aaa value) {
      this.listof_aaa = value;
    }

    // other getters and setters
    // and an example of multiple elements under the root

    public java.util.List<Listinside> getListinside() {
    if (listinside == null) {
        listinside = new ArrayList<Listinside>();
    }
    return this.sec;
}
}