May 6, 2009

0 Use of Elements vs Attributes

Data can be stored in child elements or in attributes.

Take a look at this tutorials.

<person sex="female">
<firstname>Anna</firstname>
<lastname>smith</lastname>
</person>

--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------

<person>
<sex>Female</sex>
<lastname>smith</lastname>
</person>




In the first tutorial 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.

0 comments:

Post a Comment

Blogger Themes

 
Powered by Blogger