We used some content analysis in our previous article to uncover how to create XML elements and taxonomies. As a refresher, XML elements are made up of other elements and text or content. You can use attributes to further define and give more information about your elements or the content that they contain. In this example, we will create a new element called <album> and give it an attribute called <genre> to provide a better idea of what the content is all about:
<album genre="Rock and Roll"/>
This tells us that the album's genre is rock and roll. It is equivalent to using this code:
<album>
<genre> Rock and Roll </genre>
</album>
Which method you should use is largely a matter of opinion, but here are some guidelines for you to ask yourself:
Is part of your goal to give definition to a certain part of your element? An example would be the need to give information about a physical aspect of something, such as height, weight, width and so forth.
Would you like to give more information about unique instances of an element? For instance, if you sold iPods, and some were white and others were red.
Do you want to include more information with an element when it is being used?
If you answer yes to these questions, then you may wish to use the attribute method. As an example, perhaps you are doing a report on all of the albums sold. If you use <genre> as an attribute of <album>, the genre information will always be available on your report, as opposed to having to specify that yes, you would like to retrieve the genre as well.