News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

Use of Elements vs. Attributes

Started by ben2ong2, October 05, 2006, 05:05:43 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ben2ong2

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.

You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login