<< Chapter < Page Chapter >> Page >

The start tag may also contain namespace information. There is no namespace information in Listing 2. You will learn about namespaces in a futurelesson.

The content

The set of characters in between the tags constitutes the content .

An attribute

The set of characters following the word chap in the start tag constitutes an attribute .

The term attribute is commonly used in computer science and usually has about the same meaning, regardless of whether the discussion revolves around XML, Javaprogramming, or database management. An attribute often serves to partially describe the thing to which it refers.

Things have attributes

A chapter in a book is a thing and a chapter has attributes such as its number. A person is also a thing. Therefore,a person also has attributes. Each attribute has a value. Here is a list of some of the attributes (along with their values) that might be used to describe a person:

  • name="Joe"
  • height="84"
  • weight="176"
  • complexion="pale"
  • sex="male"
  • training="Java programmer"
  • degree="Masters"

Obviously, there are many more attributes that could be used to describe a person.

The importance of an attribute depends on the context

Whether or not a particular attribute for a person is important depends on the context in which the person is being considered. For example, if the personis being considered in the context of a candidate for a basketball team, the height, weight, and sex attributes will probably be important.

On the other hand, if the person is being considered in the context of a candidate for employment as a computer programmer, the height, weight, and sexattributes should not be important at all, but the training and degree attributes might be very important.

Why does XML use attributes?

The description of XML that I provided in an earlier lesson is repeated here for convenience:

"XML gives us a way to create and maintain structured documents in plain text that can be rendered in a variety of different ways."

Attributes often provide information that is needed for the rendering process, but attributes have many other uses as well.

Rendering

I suggested earlier that the most common modern use of the word rendering means to present something for human consumption. I gave an example of anewspaper that can either be rendered on newsprint paper or can be rendered on a computer screen.

A rendering engine

If the newspaper (structured document) is created and maintained as an XML document, then some sort of computer program (often referred to as a rendering engine) will probably be used to render it into the desired presentation format.

This document

For example, the original version of this document was created as a special flavor of an XML document known as an XHTML document. Listing 3 shows a short sample of the raw XML code in the originaldocument.

Listing 3 . A section of raw XHTML code.
<p><strong style="color:#ff0000" ">A rendering engine "</strong></p><p>If the newspaper (structured document) is created and maintained as an XML document, thensome sort of computer program (often referred to as a rendering engine) will probably be used torender it into the desired presentation format.</p><p>For example, this document is a special flavor of an XML document known as an XHTML document.Listing 3 shows a short sample of the raw XML code that was delivered to your computer from mywebsite.</p>

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Introduction to xml. OpenStax CNX. Dec 02, 2014 Download for free at https://legacy.cnx.org/content/col11207/1.18
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Introduction to xml' conversation and receive update notifications?

Ask