W3C home > Mailing lists > Public > www-rdf-comments@w3.org > April to June 2001

et tu Brute?, et tu ( Use of Elements vs. Attributes (from www.xml101.com))

From: Warren Langdon <warren.langdon@ipseal.com>
Date: Tue, 19 Jun 2001 14:42:12 -0600
Message-ID: <F123CB328345C142B5A309C096277F5007EE15@po.secure.ipseal.com>
To: <www-rdf-comments@w3.org>


>  -----Original Message-----
> From: 	Warren Langdon  
> Sent:	Tuesday, June 19, 2001 10:17 AM
> To:	All ipSEAL
> Subject:	Use of Elements vs. Attributes (from www.xml101.com)
> 
> Use of Elements vs. Attributes
> 
> Take a look at these examples:
> 
> Using an Attribute for sex:
> 
> <person sex="female"> 
> 	<firstname>Anna</firstname> 
> 	<lastname>Smith</lastname> 
> </person> 
> 
> 
>  Using an Element for sex:
> 
> <person>
> 	 <sex>female</sex>
> 	 <firstname>Anna</firstname> 
> 	<lastname>Smith</lastname>
>  </person>
> 
> In the first example sex is an attribute. In the last example sex is
> an element. Both examples provides the same information to the reader.
> 
> There are no fixed rules about when to use attributes to describe
> data, and when to use elements. My experience is however; that
> attributes are handy in HTML,
>  but in XML you should try to avoid them, as long as the same
> information can be expressed using elements.
> 
> 
> Avoid using attributes? (I say yes!)
> 
> Why should you avoid using attributes? Should you just take my word
> for it? 
> These are some of the problems using attributes:
> attributes can not contain multiple values (elements can)
> attributes are not expandable (for future changes)
> attributes can not describe structures (like child elements can)
> attributes are more difficult to manipulate by program code
> attribute values are not easy to test against a DTD
> 
> If you start using attributes as containers for XML data, you might
> end up with documents that are both difficult to maintain and to
> manipulate. What I'm trying to say is that you should use elements to
> describe your data. Use attributes only to provide information that is
> not relevant to the reader. Please don't end up like this:
> 
> <?xml version="1.0"?> <note day="12" month="11" year="99"
> to="Tove" from="Jani" heading="Reminder"
> body="Don't forget me this weekend!"> </note> 
> 
> This doesn't look much like XML. Got the point?
Received on Tuesday, 19 June 2001 16:41:59 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 21 September 2012 14:16:28 GMT