简体   繁体   中英

How to unmarshal nested dynamic xml without xsd?

I'm able to unmurshal a single occurrence of a dynamic xml instantiating java classes (a wrapper and an adapter), but I don't understand how to extend this mechanism to a list of occurrences; the xml is like

<ALLRECORDSDATASET>
  <RECORD>
    <FIELD_0001>000248031</FIELD_0001>
    <FIELD_0022>A</FIELD_0022>
    <FIELD_0031>0</FIELD_0031>
    <FIELD_0033>1994-01-01</FIELD_0033>
  </RECORD>
  <RECORD>
    <FIELD_0001>000248056</FIELD_0001>
    <FIELD_0027>ABC</FIELD_0027>
    <FIELD_0037>DEF</FIELD_0037>
    <FIELD_0040>1994-01-01</FIELD_0040>
  </RECORD>
</ALLRECORDSDATASET>

and I can get the last values of RECORD (having a Record class containing a Fields class using @XmlAnyElement annotation), but I can't get all the RECORD list. Can anyone help me? Thanks

Thats one way of doing that

@XmlRootElement(name = "ALLRECORDSDATASET")
@XmlAccessorType(XmlAccessType.NONE)
public class DataSet {

    @XmlElements({ @XmlElement(name = "RECORD", type = Record.class) })
    private List<Record> records;

}

@XmlAccessorType(XmlAccessType.NONE)
public class Record {

    @XmlElement(name = "FIELD_0001")
    private String field;
    // ....
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM