This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I have a case where some data must be pesistent (using XML) adn I must design the XML document.Here I have two options for every data property I create a new (sub)node or I have less nodes and I use the node attributes. By example : if I have a page with size x, size Y and name attributes and I use the first option (only nodes) I have something like : <paper> <sizeX> <100mm/> </sizeX>
<sizeX> <100mm/> </sizeX>
<name> <paperName ........../> </name>
If I use the second concept less nodes and some attributes I have : <page> <size x="100mm" y="300mm"/> <name paperName="Paper1"> <page>
I think the secont try (less nodes and some attributes) reflect better my data ,at least from the oop point of view. Is this right ?
This is a classic topic for discussion. I have been working with a client's XML that is ALL elements with no attributes - it is much bulkier and (IMHO)harder to read than a thoughtful mix of attributes and elements. I would suggest the following guidelines: 1. be mindful of the limits on characters that can be used in an attribute 2. think of attributes as adjectives modifying an Element noun - for your example the page could be modified by sizeX and sizeY attributes rather than living in a size element. 3. properties that have a limited number of values - such as your sizeX or (for example) color make a good choice for attributes. Look at HTML for example. Bill