- From: Warren Langdon <warren.langdon@ipseal.com>
- Date: Tue, 19 Jun 2001 14:42:12 -0600
- 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 UTC