• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple question

 
Jared Sprague
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the rule for when to use an attribute or when to use the body of the tag.
For example in what case would you want to use this:
<user name="bob" />

And when would you use this:
<user>bob</user>

I'm just wondering how you decide which is more appropriate.

Thank you!
 
Andy Smith
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The questions realtes to when to create a attribute ?

1. When the data needs to be idetified uniquely, u shud go for Attribute. As if the atribute is of ID type it is unique...

2. U can also use ID/ IDREFS with attribute..

3. U can fix the value domain for the attribute values using the Enumeration..

There are many more... please add to this....
 
Hari Vignesh Padmanaban
Ranch Hand
Posts: 578
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jared Sprague:
What is the rule for when to use an attribute or when to use the body of the tag.
For example in what case would you want to use this:
<user name="bob" />

And when would you use this:
<user>bob</user>

I'm just wondering how you decide which is more appropriate.

Thank you!


Well that is a life long debate which i am sure would never end

There is no rule as such. Its a matter of personal preference
See these links

http://www-106.ibm.com/developerworks/xml/library/x-eleatt.html
http://www.ucc.ie/xml/#attriborelem

Enjoy


HTH
Hari
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic