Ryan's District Boards

Computer, programming, and webmaster help , support , tips and tricks => Tutorials Zone! => Internet webmaster computer programming technology tips and tricks => XML Tutorials => Topic started by: ben2ong2 on October 05, 2006, 05:05:43 PM

Title: Use of Elements vs. Attributes
Post by: ben2ong2 on October 05, 2006, 05:05:43 PM
Data can be stored in child elements or in attributes.
Take a look at these examples:
<person sex="female">  <firstname>Anna</firstname>  <lastname>Smith</lastname></person>

<person>  <sex>female</sex>  <firstname>Anna</firstname>  <lastname>Smith</lastname></person>
In the first example sex is an attribute. In the last, sex is a child element. Both examples provide the same information.
There are no rules about when to use attributes, and when to use child elements. My experience is that attributes are handy in HTML, but in XML you should try to avoid them. Use child elements if the information feels like data.