I'm looking for a way to map all the attributes of an XML element into a single HashMap using MOXy (with an external OXM file) but I can't seem to find any information on it. I can't seem to find any references to dealing with multiple, unspecified attributes with either XmlAdapter instances or XmlTransformation instances.
If I have the below XML file and wish to marshal it into the below class, what would the best approach be?
Note that I can handle the "value" elements fine, it's the attributes I'm having trouble with; they should ideally map the XML attributes as...
[{"name", "firstElement"}, {"id", "idOne"}, {"author", "joeBloggs"}]
XML File:
<?xml version="1.0" encoding="UTF-8"?>
<root_node>
<element name="firstElement" id="idOne" author="joeBloggs">
<value>1</value>
<value>2</value>
<value>3</value>
</element>
</root_node>
Java Class:
public class Element {
public Map<String, String> attributes;
public List<Integer> values;
public List<String> getValues() {
if(values == null) {
values = new ArrayList<>();
}
return values;
}
public Map<String, String> getAttributes() {
if(attributes == null) {
attributes = new HashMap<>();
}
return attributes;
}
}