Search code examples
javaxmlparsingconfigurationstax

StAX Parsing - where to keep element schemas?


I need to write a parser to save data from XML in the format:

<!-- Sample XML>
<Results>
    <TableA>
        <ID>7</ID>
        <Name>Joe</Name>
    </TableA>
    <TableA>
        <ID>8</ID>
        <Name>John</Name>
    </TableA>
</Results>

Into a Map<String, Object>[]. Each TableA element will be one map of name/value pairs.

I'll have a great number of different tables this has to work for, each having its own schema with different name/value pairs, but the same layout. I don't plan to mix results from different tables - I just want a generic way of loading the schema and parsing the similar documents.

So, what's the best way to store/make use of the schemas in Java? I'm still reasonably new to it and don't know the conventions well yet. I obviously don't want to hard code them. Is Spring the best option or are there other alternatives?


Solution

  • No answer after 17 days, so writing what my solution ended up being:

    We stored the schemas in spring as maps, and loaded the beans directly to use in the parser. It seems to work fairly well and be reasonably flexible.