Java 使用JAXB解组xml项的复杂嵌套列表

Java 使用JAXB解组xml项的复杂嵌套列表,java,jaxb,Java,Jaxb,我正在尝试解压这个复杂的xml,但未能成功。下面是我的xml: <ImportSession xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Batches> <Batch BatchClassName="BC"> <BatchFields> <BatchField Name="N11&qu

我正在尝试解压这个复杂的xml,但未能成功。下面是我的xml:

<ImportSession xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Batches>
    <Batch BatchClassName="BC">
      <BatchFields>
        <BatchField Name="N11" Value="N21"/>
        <BatchField Name="N12" Value="N22"/>
        <BatchField Name="N13" Value="N23"/>
        <BatchField Name="N14" Value="N24"/>
        <BatchField Name="N15" Value="N25"/>
      </BatchFields>
      <Documents>
        <Document FormTypeName="F1">
          <IndexFields>
            <IndexField Name="NM11" Value="V11"/>
            <IndexField Name="NM12" Value="V12"/>
            <IndexField Name="NM13" Value="V13"/>
            <IndexField Name="NM14" Value="V14"/>
         </IndexFields>
         <Pages>
           <Page ImportFileName="P1.pdf"/>
         </Pages>
       </Document>
       <Document FormTypeName="F2">
         <IndexFields>
           <IndexField Name="NM21" Value="V21"/>
           <IndexField Name="NM22" Value="V22"/>
           <IndexField Name="NM23" Value="V23"/>
           <IndexField Name="NM24" Value="V24"/>
        </IndexFields>
        <Pages>
          <Page ImportFileName="P2.pdf"/>
        </Pages>
      </Document>
      <Document FormTypeName="F3">
        <IndexFields>
          <IndexField Name="NM31" Value="V31"/>
          <IndexField Name="NM32" Value="V32"/>
          <IndexField Name="NM33" Value="V33"/>
          <IndexField Name="NM34" Value="V34"/>
        </IndexFields>
        <Pages>
          <Page ImportFileName="P3.pdf"/>
        </Pages>
        </Document>
      </Documents>
    </Batch>
  </Batches>
</ImportSession>
在我的文档课上,如果我有

private Document document;
它工作得很好,但它只提供了xml的最后一个文档。但如果我想说:

private List<Document> document;
私有列表文件;
代码出来时什么都没有,也没有错误。需要帮助分析我缺少的东西


我不希望在输出中包含BatchFields/BatchField,因此在我的类架构中没有相同的内容。

我已经使用
xjc
生成了java类
ImportSession.java
,并得到了不同的结果

import java.util.ArrayList;
导入java.util.List;
导入javax.xml.bind.annotation.XmlAccessType;
导入javax.xml.bind.annotation.XmlAccessorType;
导入javax.xml.bind.annotation.XmlAttribute;
导入javax.xml.bind.annotation.xmlement;
导入javax.xml.bind.annotation.XmlRootElement;
导入javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name=),比例={
“批次”
})
@XmlRootElement(name=“ImportSession”)
公共类导入{
@xmlement(name=“Batches”,required=true)
受保护的导入会话。批处理;
public-ImportSession.Batches-getBatches(){
退货批次;
}
公共作废收单批次(ImportSession.Batches值){
这是一个值;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name=),比例={
“批量”
})
公共静态类批处理{
@xmlement(name=“Batch”,required=true)
受保护的导入会话.Batches.Batch;
public ImportSession.Batches.Batch getBatch(){
退货批次;
}
public void setBatch(ImportSession.Batches.Batch值){
this.batch=值;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name=),比例={
“批处理字段”,
“文件”
})
公共静态类批处理{
@xmlement(name=“BatchFields”,必需=true)
受保护的ImportSession.Batchs.Batch.BatchFields批处理字段;
@xmlement(name=“Documents”,required=true)
受保护的ImportSession.Batches.Batch.Documents文件;
@XmlAttribute(name=“BatchClassName”,必需=true)
受保护的字符串batchClassName;
public ImportSession.Batchs.Batch.BatchFields getBatchFields(){
返回批处理字段;
}
公共字段(ImportSession.Batches.Batch.BatchFields值){
this.batchFields=值;
}
public ImportSession.Batches.Batch.Documents getDocuments(){
归还文件;
}
public void setDocuments(ImportSession.Batches.Batch.Documents值){
本文件=价值;
}
公共字符串getBatchClassName(){
返回batchClassName;
}
public void setBatchClassName(字符串值){
this.batchClassName=值;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name=),比例={
“批处理字段”
})
公共静态类批处理字段{
@xmlement(name=“BatchField”,必需=true)
受保护列表字段;
公共列表getBatchField(){
if(batchField==null){
batchField=新的ArrayList();
}
返回此.batchField;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name=”“)
公共静态类批处理字段{
@XmlAttribute(name=“name”,required=true)
受保护的字符串名称;
@XmlAttribute(name=“Value”,required=true)
保护字符串值;
公共字符串getName(){
返回名称;
}
公共void集合名(字符串值){
this.name=值;
}
公共字符串getValue(){
返回值;
}
公共void设置值(字符串值){
这个值=值;
}
}
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name=),比例={
“文件”
})
公共静态类文档{
@xmlement(name=“Document”,required=true)
受保护清单文件;
公共列表getDocument(){
if(document==null){
document=newarraylist();
}
归还本文件;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name=),比例={
“索引字段”,
“页面”
})
公共静态类文档{
@xmlement(name=“IndexFields”,必需=true)
受保护的ImportSession.Batch.Batch.Documents.Document.IndexFields IndexFields;
@xmlement(name=“Pages”,required=true)
受保护的导入会话.Batches.Batch.Documents.Document.Pages;
@XmlAttribute(name=“FormTypeName”,必需=true)
受保护的字符串formTypeName;
public ImportSession.Batch.Batch.Documents.Document.IndexFields getIndexFields(){
返回索引字段;
}
public void setIndexFields(ImportSession.Batches.Batch.Docum
private Document document;
private List<Document> document;
@XmlElement(name = "Document")
private Document document;
@XmlElement(name = "Document")
private List<Document> documents;
<Documents>
  <Document ...>...</Document>
  <Document ...>...</Document>
  <Document ...>...</Document>    
</Documents>
@XmlElement(name = "Documents")
private Documents documents;
@XmlElementWrapper(name = "Documents")
@XmlElement(name = "Document")
private List<Document> documents;