|
XML Made Easy
By Stephen Bucaro
Many people think that XML (Extensible Markup Language) is a replacement for HTML.
XML and HTML are both "markup languages". A markup language consists of tags that
are added to text to change the look or meaning of the text. After XML or HTML tags
are added to the text, the text is called "code". Below is an example of HTML code.
Wiew Code
This HTML code defines how the text will be displayed. It defines the font face,
font size, and color of the text. It defines that the text will be displayed as
a column. HTML is about displaying information, but it tells you nothing about the
information. Below is an example of XML code.
Wiew Code
This XML code defines the meaning of the text. It defines a "name" data element
within a "members" element. Each name contains a "first" and "last" element. It
defines that the members element can contain multiple name elements. XML is about
describing information, but it tells you nothing about how to display the information.
The intent of this article is to give you a top-down understanding of XML, so I
don't want to go into every detail of the code. Briefly, the top line of the code above
is the "XML declaration" The section below that is the "document type declaration" (DTD).
It defines the structure of a document of type "members". The section below the DTD is
the "document element". It contains all the data in the XML document.
I know what your thinking. So how do I display the XML data on my Web page? That is
accomplished by binding the XML elements to HTML elements. Below is an example.
Wiew Code
The first line in the body of the HTML code above links the XML document to the Web
page. This creates a "data island" in the HTML page. Notice that I assigned the
identifier "memberlist" to the data island. The next line binds the entire data
island to an HTML table. The table defines a single row with two data elements. The
first data element contains a span bound to the "first" datafield. The second data
element contains a span bound to the "last" datafield. When the browser displays
the table, it automatically repeats the row element for each record in the XML document.
Wiew Code
Did you notice the word "record" in the last sentence. When Internet Explorer opens
the Web page, it creates a database called the "Data Source Object" (DSO). The DSO
stores each name as a record with each first element and last element as fields in the record.
|