• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

XML design, more nodes or more attributes ?

 
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Opps new I see I post my aticle 3 times
Sorry !
The frist 2 are whitout meaning but i can not remove them.
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all useful tips.
How about some desingn opinion about my XML document design ?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic