SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Threaded View

  1. #1
    SitePoint Member linde002's Avatar
    Join Date
    Jun 2007
    Location
    Hoorn, The Netherlands
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wrapping DOM in objects - what kind of approach?

    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:
    Code:
    <?xml version='1.0' encoding='UTF-8'?>
    <form id='form001' code='form001' version='1' description='form001_desc'>
       <dimensions>
          <dimension id='dim_01'>
             <levels>
                <level id='dim_01_l01' depth='1'>
                   <members>
                      <member id='dim_01_l02_m01
                   </members>
                </level>
             </levels>
          </dimension>
       </dimensions>
       <cubes>
          <cube id='c01'>
             <axiss>
                <axis id='rows'>
                   <dimensionlist>
                      <dimensionref dimensionid='dim_01'/>
                   </dimensionlist>
                   <tupels>
                      <tupel id='r_1'>
                         <memberref memberid='dim_01_l02_m01'/>
                      </tupel>
                   </tupels>
                </axis>
             </axiss>
          </cube>   
       </cubes>
    </form>
    As you can see the reocurring pattern is a 'container' element like 'dimensions' which hold the 'real' elements, in this case 'dimension'.

    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
    • form
    • dimension
    • level
    • member
    • cube
    • (...)


    the Form object would have the following attributes and methods
    • sID
    • sCode
    • sVersion
    • sDescription
    • aDimensions
    • aCubes
    • setAttribute()
    • getAttribute()
    • addCube()
    • getCube()
    • delCube()
    • addDimension()
    • getDimension()
    • delDimension()
    • getXML()


    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:
    Code:
       Form
         Dimension
            Level
              Member
    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.
    Last edited by linde002; Jun 6, 2007 at 13:00. Reason: Uncompleted sentence


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •