I am struggling to come up with a clear, readable, usable and OO-friendly approach to parse and manipulate a custom xml format using objects which represent the xml elements. To illustrate here is a basic xml file using this format:
As you can see the reocurring pattern is a 'container' element like 'dimensions' which hold the 'real' elements, in this case 'dimension'.
<?xml version='1.0' encoding='UTF-8'?>
<form id='form001' code='form001' version='1' description='form001_desc'>
<level id='dim_01_l01' depth='1'>
The complete xml format has many more elements (not every container element has only one type of child element) but I choose not to show them here as they would only waste space. The overal concept is the same as showed above.
The approach I've narrowed in on is that of a builder class, say FormEditor, which works with Object representations of the 'real' elements.
In this example those objects would be
the Form object would have the following attributes and methods
The other Objects would all use this kind of approach. The function of the getXML() method creates a DOMElement object with the tagname of the element the object is representing, that would be <form> in this example.
Then it would set all the attributes, after this it would loop over the aDimensions and aCubes array and then call the getXML() method on these objects.
getXML finally returns the DOMElement object.
My problem now is: (yes finally ) How would I retrieve a specific Member Object from the top-level Form Element because the Member object is waaaay down in the object hierarchy:
Does anyone who's been able to decypher this riddle have any insights how I should go about creating this? Am I way wrong or just a nudge in the good direction away from my answer?
P.S. I apologize if some of my concepts are badly explained. English not my mother tongue.