I have seen a lot of similar problems that keep getting me partway there, but I end up starting to have to build recursive solutions on top which I'm trying to avoid.
I have an XML file I want to convert into a map.
The structure is unknown except for one thing
<items>
<item>
{section to be converted to map}
</item>
<item>
{section to be converted to map}
</item>
</items>
All the solutions I've seen seem to be converting the entire thing into map, or parse through each attribute/value manually.
I'm wondering if there's a method to say...
Jump into items, jump into each item, convert each item to map, then I can process each map individually.
I am streaming through a potentially large file, so don't want to hold the entire thing in memory, just one item at a time.
I have tried to use xmleventreader to do this, but get jammed up in a recursive nightmare. The item was for the event reader to find individual items, and them on those individual items to have them process, but not finding any documentation on how to capture what's between each value so it can be processed as an XML later.
private void parseItemList(MultipartFile file) {
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
try {
XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(file.getInputStream());
processItems(xmlEventReader);
} catch (FileNotFoundException | XMLStreamException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
The idea would be to convert:
<items>
<item>
<id>1</id>
<value>4</value>
</item>
<item>
<id>2</id>
<attributes>
<value>5</value>
</attributes>
</item>
</items>
into
{id: 1, value: 4}
{id: 2, attributes{value: 5}}
and so on, where I can process and push each map individually before moving onto the next. If there's a library that handles this easily, I'd love to be pointed in that direction.