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>
</paper>
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
You are right the a xml document where nearly all elements are nodes is somehow hard to read because of the big amount of data(s).
What means IMHO ?
On your second point, I choose to let the size attributes in to a node because the same size node(syntax) is used to define other "sizes". What you think about ?
And to put together your 3 points -> attributes are good in the right quantity.
On your second point, I choose to let the size attributes in to a node because the same size node(syntax) is used to define other "sizes". What you think about ?
I guess it depends on your particular data problem and how you need to process size data. If you later decide to change the way it is used, you can usually come up with an XSLT to rearrange the data.
IMHO = "In My Humble Opinion" Bill
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
Gift giving made easy with the permaculture playing cards