I'm using xmlbeans to access xml documents based on Oagis canonicals.  The nesting can get extreme.  For instance, I need to access/set an element 7 levels deep.  Is there a best practice for this scenario.
 
I have a few possible solutions but I'm not pleased with either.
 
My scenario:
 
I have to pull invoice data from "n" different db2 as/400 tables to populate a canonical and publish the canonical to a JMS topic.
 
So, I create an instance like this:
invoice = ShowInvoiceDocument.Factory.newInstance(); 
 
To set a value 7 levels deep, looks like I can do something really bad like:
 
InvoiceHeaderType invoiceHeaderType = invoice.addNewLevel1Object().addNewLevel2Object().addNewLevel3Object().add... 
invoiceHeaderType.setCustomerDiscount(some_value_from_the_db);
 
...the last addNewLevel7Object of course being of type InvoiceHeaderType.  Again, very bad design - I know - hard to unit test among breaking other pragmatic programmer rules :-).
 
The other approach I dreamed up would be to instantiate invoice (global) then create objects for all other levels and call the next addNew...() methods until I have all 7.  For example:
 
invoice = ShowInvoiceDocument.Factory.newInstance();
aInvoice = invoice.addNewShowInvoice();
anInvoiceDataArea = aInvoice.addNewDataArea();
aDataAreaInvoice = anInvoiceDataArea.addNewInvoice();
aDataAreaInvoiceHeader = aDataAreaInvoice.addNewInvoiceHeader();
...
 
Then call setCustomerDiscount(some_value_from_the_db) on the last level object and save().
 
Is there a roadmap for this already?  Thanks in advance for your feedback.

Reply via email to