So I have a couple of XMLs which I'm trying to unmarshal.
One XML can look like this:
<TABLE>
<RECORDS>
<RECORD>
<DOC_ID>some value</DOC_ID>
<ENTITY_ID>some value</ENTITY_ID>
...more entries
</RECORD>
<RECORD>
<DOC_ID>some value</DOC_ID>
<ENTITY_ID>some value</ENTITY_ID>
...more entries
</RECORD>
</RECORDS>
</TABLE>
Another XML can also look like this:
<TABLE>
<RECORDS>
<RECORD>
<SUB_ID>some value</SUB_ID>
<CASE_DOC_ID>some value</CASE_DOC_ID>
...more entries
</RECORD>
<RECORD>
<SUB_ID>some value</SUB_ID>
<CASE_DOC_ID>some value</CASE_DOC_ID>
...more entries
</RECORD>
</RECORDS>
</TABLE>
Each XML always has TABLE as root and RECORDS as a child and RECORD as grandchild just that the data in RECORD is different.
I don't want to marshal anything, just unmarshal and get the data.
Inside my Table Class I have
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "TABLE")
public class Table {
@XmlJavaTypeAdapter(MapAdapter.class)
private Map<String, String> RECORDS;
public Map<String, String> getMap() {
return RECORDS;
}
public void setMap(Map<String, String> record) {
this.RECORDS = record;
}
}
I took MapAdapter from this link: JAXB Marshal and Unmarshal Map to/from <key>value</key>
My issue is this: I would like to be able to get each Tag name in the record (DOC_ID/SUB_ID or whatever in the XML) and each of it's values as Strings when I pass in the XML but I'm not sure how to go about it.
Any help to point me in the right direction would be appreciated.
EDIT:
2 new questions! I realized I would probably need a list of Maps for all the records.
- I managed to get the last record's keys and values using the Table class above. How do I turn it into a list of Maps so I can get each record instead of just the last?
- Another question is the Table class only works if I don't have a RECORDS tag in my xml. How do I fix that?