XML demonstration

Exercise 5 - XML Attributes

  1. Open poor_job.xml in your browser window.
    In this document, gender is an attribute of the <name> element. In XML, unlike HTML, attribute values must be enclosed in either single or double quotes. In this instance, gender represents important information; it helps distinguish between the two applicants named Sam. It would be better to convey this information via a separate <gender> element rather than as an attribute of the <name> element.
  2. Open better_job.xml in your browser window.
    This document is well designed. It includes <gender> as a child element of <applicant> and a sibling element of <name>. In XML, data is more easily manipulated when placed in separate elements rather than conveyed as attributes of other elements.
  3. Open phone.xml in your browser window.
    In this document, preferred is an attribute of phone_1 and phone_2. Here it is more appropriate to use an attribute, as the values convey information about the data rather than being data in their own right. As a general rule, use elements for data and attributes for metadata, or data about data. However, when in doubt, donít use attributes.

Home page