You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by "Ruffin, John" <jr...@achfood.com> on 2006/02/09 07:44:22 UTC
Accessing deeply nested elements
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().a
dd...
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.