Custom Subprogram and web service - how to return nested arrays

I'm trying to return data for an array of parent/child items in a custom X3 web service (Version 12).  Specifically, I'm trying to get invoice data.  Normally, I would just publish the appropriate object as a web service, and I could make a call to get that object and it's detail lines.  However, I want to be able to return several objects at once -- say, I want to take as input a starting invoice number and an ending invoice number.  The output would be XML of an array of invoices.  Is there a way to do this and expose it as a web service?  I can create fields for the header items with a certain number of dimensions, but how do I dimension XML fields for the detail lines at this nested level?  I could create a group with a TAB full of header info and a second with a TAB full of details, but I'd have to include some way to link each detail line back to a specific header record in the first group.  I want to keep the details as a sub-node of each header record.