Page 218 - DCAP312_WEB_TECHNOLOGIES_II
P. 218
Web Technologies-II
Notes If you consider the information to be peripheral or incidental to the main communication, or
purely intended to help applications process the main communication, use attributes. This avoids
cluttering up the core content with auxiliary material. For machine-oriented records formats,
this generally means application-specific notations on the main data from the problem-domain.
Principle of Structured Information
If the information is expressed in a structured form, especially if the structure may be extensible,
use elements. On the other hand: If the information is expressed as an atomic token, use attributes.
Elements are the extensible engine for expressing structure in XML. Almost all XML processing
tools are designed around this fact, and if you break down structured information properly into
elements, you will find that your processing tools complement your design, and that you thereby
gain productivity and maintainability. Attributes are designed for expressing simple properties
of the information represented in an element. If you work against the basic architecture of XML
by shoehorning structured information into attributes you may gain some specious terseness
and convenience, but you will probably pay in maintenance costs.
Dates are a good example: A date has fixed structure and generally acts as a single token, so it
makes sense as an attribute (preferably expressed in ISO-8601). A personal name has surprisingly
variable structure (in some cultures you can cause confusion or offense by omitting honorifics
or assuming an order of parts of names). A personal name is also rarely an atomic token. As
an example, sometimes you may want to search or sort by a forename and sometimes by a
surname. Thus:
<customer>
<name>Gabriel Okara</name>
<occupation>Poet</occupation>
</customer>
is not much better than:
<customer name= “Gabriel Okara”>
<occupation>Poet</occupation>
</customer>
Principle of Readability
If the information is intended to be read and understood by a person, use elements. In general
this guideline places prose in element content. If the information is most readily understood and
digested by a machine, use attributes. In general this guideline means that information tokens
that are not natural language go in attributes.
In some cases, people can decipher the information being represented but need a machine to use
it properly. URLs are a great example: People have learned to read URLs through exposure in
Web browsers and e-mail messages, but a URL is usually not much use without the computer
to retrieve the referenced resource. Some database identifiers are also quite readable (although
established database management best practice discourages using IDs that could have business
meaning), but such IDs are usually props for machine processing.
Principle of Element/Attribute Binding
Use an element if you need its value to be modified by another attribute. XML establishes a very
strong conceptual bond between an attribute and the element in which it appears. An attribute
provides some property or modification of that particular element. Processing tools for XML
tend to follow this concept and it is almost always a terrible idea to have one attribute modify
another. For example, if you are designing a format for a restaurant menu and you include
the portion sizes of items on the menu, you may decide that this is not really important to the
212 LOVELY PROFESSIONAL UNIVERSITY