How to unmarshal nested dynamic xml without xsd?

250
June 10, 2017, at 11:19 PM

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

Answer 1

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;
    // ....
}
READ ALSO
How to completely set all objects null in a Jframe? [duplicate]

How to completely set all objects null in a Jframe? [duplicate]

This question already has an answer here:

305
Closest Point - Flaw in approach

Closest Point - Flaw in approach

I am solving Closest Point Problem from here

194
Determining which overrides method is actually invoked

Determining which overrides method is actually invoked

When a subclass object is casted to its superclass, for example

148