File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes XML design, more nodes or more attributes ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML design, more nodes or more attributes ?" Watch "XML design, more nodes or more attributes ?" New topic
Author

XML design, more nodes or more attributes ?

Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hallo !

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 ?


SCJP, SCJD, SCWCD, OCPJBCD
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Opps new I see I post my aticle 3 times
Sorry !
The frist 2 are whitout meaning but i can not remove them.
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by Mihai Radulescu:
The frist 2 are whitout meaning but i can not remove them.

I have removed the other two post for you.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Mihai Radulescu:
Opps new I see I post my aticle 3 times
Sorry !
The frist 2 are whitout meaning but i can not remove them.

No problem. But you actually should be able to remove them using the following steps:

1. open the thread you want to delete
2. click the button of the first post in that thread
3. check the "delete post" checkbox and submit the form


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Thanks for all useful tips.
How about some desingn opinion about my XML document design ?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12786
    
    5
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
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Tannks for tips William.

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.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12786
    
    5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML design, more nodes or more attributes ?