Understanding HTML Basics

Before we begin using the basic components of an XML document to create Web applications, we must cover some basics of HTML documents. Unlike XML, HTML markup does not always define content within the markup. For example, HTML includes a set of tags that do not contain anything, such as <hr>, <img>, and <br>. These elements do not have end tags in HTML; if you include end tags with these elements, the Web browser will ignore them.

Logical and Physical HTML Elements

For the most part, elements and attributes in HTML can be divided into two groups: physical and logical. A logical HTML element or attribute is similar to an XML element. Logical elements and attributes describe the format of the content enclosed within the tags. For example, here the text Hello, world should be displayed with a font size of 3:

  <font size="3">Hello, world</font>

The actual size of the font will depend on the browser settings and the user's preferences. With logical elements, the Web browser will use the markup elements and attributes to identify what the content is and then display the content accordingly.

Physical elements and attributes do not give the user any options as to how content is displayed-they define exactly what the content will look like. Rewriting our font size example using a physical attribute, we have:

  <font size="12 pt">Hello, world</font>

The Hello, world text will now always be displayed in 12 point type, regardless of the user's preferences. The attribute no longer defines the content as being of a certain format that the application will interpret; it simply sets the attribute to a value that the application will use.

When you develop XML applications, you will want to define elements and attributes that give the user more control, such as logical HTML elements and attributes. These elements and attributes will be used by the application to identify the content contained within the element. Once the application understands what the content is, it can determine how to use the content based on user preferences (for example, setting the default size 3 text to 14 point text in the browser), the structure of the database (for example, in one corporation a customer's last and first names might be saved as a single entity called CustomerName, and in another corporation the same information might be saved as LName and FName), and so on. As we create Web applications using XML throughout this tutorial, we will use logical elements and attributes whenever possible.

The main problem we will have with building Web applications using XML is that most people are working with browsers that only understand HTML. We'll need some way to get the non-XML browsers to view XML code as HTML code so that the pages will render properly in the browser. When cascading style sheets (CSS) were introduced, they also faced the same problem: how to render documents properly in non-CSS browsers. The ingenious solution that was used for CSS documents can also be used for XML. Let's take a look at how CSS can work in both browsers that understand style sheets and browsers that do not.

by BrainBellupdated