Ordered heterogeneous elements and XML mapping software


Ordered heterogeneous elements and XML mapping software

I continue to run into this problem in my schemas. I have an element and it contains a sequence of choices and I need to process it in an ordered fashion.

Here is an example slice of XML:

<requests>
 <get/>
 <get/>
 <post/>
 <get/>
 <post/>
 <post/>
</requests>

I need to get that list of <get>s and <post>s from the <requests> element in an ordered fashion and then deal with them based on their type. The XML mappers all try and give me two methods on the request object, getGets() and getPosts(), even when Gets and Posts extend the same base type. It should at least give me a getBaseTypeElements() in there somewhere. This is obviously useless. Typically there is some way to get the children elements but then I am reduced to using instanceof to figure out how to dispatch the element. I could use some sort of generic dispatch system to find the correct method to call for the current element like Ruby or Groovy would do automatically, but that would be slow and error prone. What’s the most elegant way to do this in Java? Is there an XML mapping system that has a good solution?