8. What type of technology could DHTML offer an alternative to? A. ASP B. CSS C. DOM D. XML 9. What is the name of the mechanism that responds to an event? A. Event handler B. Event manager C. Event controller D. Event developer
Copyright ©2002 SYBEX, Inc., Alameda, CA
www.sybex.com
336
Chapter 12
Dynamic HTML
10. Coupled with CSS1 and linked by script, what can DHTML be used
to replace? A. Functions currently performed by ASPs, JSPs, or PHPs B. Functions currently performed by JavaScript or VBScript C. Functions currently performed by Flash, Shockwave,
or Photoshop D. Functions currently performed by Java applets, ActiveX controls,
or animated GIFs 11. What concept was introduced with Netscape Navigator 2 in 1995? A. DHTML B. DOM C. HTML D. XML 12. What goal does the W3C have for the Document Object Model (DOM)? A. Provide a standard programming interface. B. Enable programmers to create document structure. C. Replace DHTML. D. Replace HTML. 13. What does scripting allow a programmer to do that HTML and style
sheets do not? A. Control page structure. B. Interact with tags. C. Change font color. D. Use animated GIFs.
Copyright ©2002 SYBEX, Inc., Alameda, CA
www.sybex.com
Review Questions
337
14. Which of the following is an event handler supported by both
Netscape and Microsoft browsers? A. onFocus B. onAlign C. onReload D. onDoubleclick 15. What is one way to create DHTML pages that will work with both
Netscape and Microsoft browsers? A. Use DOM along with DHTML. B. Do nothing; DHTML will always work with both browsers. C. Use a high-end HTML editor. D. Use XML along with DHTML. 16. What does DHTML add to HTML? A. Methods for formatting text B. Methods for running images C. The ability to use scroll down boxes D. The ability to change background color 17. What two products may cause the W3C to not allow DHTML time to
mature? A. HTML 4.0 and XML B. DOM and HTML C. JavaScript and Java D. XML and XSL
Copyright ©2002 SYBEX, Inc., Alameda, CA
www.sybex.com
338
Chapter 12
Dynamic HTML
18. HTML 4 supports what W3C Recommendation, which includes typo-
graphical control elements? A. XML B. CSS1 C. DHTML D. DOM 19. Which of the following is an event handler in an HTML document? A. Quickload B. Halfload C. Site Split D. onLoad 20. Even when using a high-end HTML editor to create cross-browser
DHTML code, it still contains ___________________ . A. XML code B.
tag C. Browser-specific code D. Deprecated tags
Copyright ©2002 SYBEX, Inc., Alameda, CA
www.sybex.com
Answers to Review Questions
339
Answers to Review Questions 1. C. Code does exist for a limited number of DHTML events that will
work in both browsers, but the range of this code is limited. In order for all DHTML events to function correctly in both Internet Explorer and Navigator, separate code must be written for each browser. 2. B. The Document Object Model (DOM) is a key component in
DHTML. It allows programmers to use objects and their associated event handlers to create events in HTML pages. It is the DHTML interface that accesses and manipulates HTML and XML documents. It also provides logical structure to these documents. 3. D. An event in an HTML document is anything that occurs during
the life of the HTML page in the browser. Events are controlled by event handlers, which perform the designated event when called upon. An example of an event is onLoad, which occurs when the HTML document is loaded in the browser window from the server. 4. B. DHTML is a set of technologies that allows the website author
to create pages that are more interactive than pages created with just HTML. 5. C. DHTML combines HTML 4.0.1 with the Document Object Model
(DOM), Cascading Style Sheets (CSS1), and a scripting language (such as JavaScript or VBScript). It allows website designers to add interactivity and interest to their websites through a combination of technologies. 6. D. The Document Object Model describes the flow of a document. It
gives programmers the ability to create document structure or add or change content. It is an essential component of DHTML. 7. A. Netscape uses the tag to implement DHTML. Layers
can be used to show, hide, or move blocks of HTML, and they can be manipulated based upon events activated by the user. 8. A. DHTML could offer an alternative to some server-side technolo-
gies such as Active Server Pages (ASPs). It provides dynamic rather than the typical static HTML content to the browser, but it doesn’t need to access the server each time it receives browser input.
Copyright ©2002 SYBEX, Inc., Alameda, CA
www.sybex.com
340
Chapter 12
Dynamic HTML
9. A. An event handler is executed when the browser detects an event
that has been mapped by the appropriate event attribute within the document. 10. D. Coupled with the CSS1 standard and linked by script, Dynamic
HTML can be used in some cases to replace functions currently performed by Java applets, ActiveX controls, or animated GIFs. DHTML brings to HTML the interactivity possible with scripting languages. 11. B. The Document Object Model (DOM) was introduced in 1995
with Netscape Navigator 2. It was developed by Netscape as a specification or instance hierarchy of JavaScript objects. 12. A. The W3C’s goal for the DOM is to provide a standard program-
ming interface that is compatible with various applications and environments yet works within existing HTML, style sheets, and scripting languages. 13. B. Scripting allows you to interact with tags and styles. It lets you
design a response or function for a user event, such as a mouse move. You can use VBScript or JavaScript to interact with the DHTML Document Object Model. 14. A. The onFocus event handler is supported by both Netscape and
Microsoft browsers. The objects associated with the onFocus event handler are Password, Text, Textarea, Window. 15. C. Many of the high-end HTML editors, such as Dreamweaver and
FrontPage, have DHTML capabilities. The advantage to using those tools is that they create a dual set of code that allows DHTML to work in either browser. 16. A. DHTML standards extend HTML by adding new methods for
formatting text and HTML page elements as well as new scripting event handlers that can trigger script with a wider variety of mouse and keyboard events. 17. D. The advances in XML and XSL can offer many DHTML features
and more, so the W3C may not spend the time to mature DHTML. 18. B. HTML 4 supports the W3C Recommendation for Cascading Style
Sheets (CSS1), which includes typographical control elements known as style sheets. With style sheets, you can create web pages with the layout sophistication of desktop publishing programs such as Microsoft Word, Adobe PageMaker, and QuarkXPress.
Copyright ©2002 SYBEX, Inc., Alameda, CA
www.sybex.com
Answers to Review Questions
341
19. D. An event in an HTML document is anything that occurs during
the life of the HTML page in the browser. The event can be as simple as a file opening or closing in the browser. The associated event handler, in this case onLoad, detects when the event occurs and then performs a defined action as a result. 20. C. Although high-end HTML editors can create cross-browser
DHTML, it still contains some browser-specific code.
Copyright ©2002 SYBEX, Inc., Alameda, CA
www.sybex.com
Chapter
13
Extensible Markup Language (XML) THE CIW EXAM OBJECTIVE GROUP COVERED IN THIS CHAPTER: Use client-side and server-side programming to enhance website functionality, including but not limited to: Extensible Markup Language (XML).
Copyright ©2002 SYBEX, Inc., Alameda, CA
www.sybex.com
E
xtensible Markup Language (XML) allows for the creation of documents for the Internet as well as for other media. It is a significant advancement that may soon allow us to create a single set of data that can be delivered on the printed page, on a CD-ROM, in HTML format, in streaming audio, and to a pager’s LCD display panel. The focus of XML is on the content of the document rather than the look of the document, which provides for greater search capabilities. Currently, HTML has a specific set of tags that do not address content but rather how a document looks in the browser. This limitation illustrates the advantages of using XML instead of HTML: the ability to create your own tags within standard guidelines of formation and the ability to create a document that can be searched easily. Unlike other technologies we have discussed thus far in this book, XML is natively supported in the most current versions of both Microsoft’s and Netscape’s browsers. In this chapter, we will explore XML and its relationship to SGML and HTML. We’ll discuss HTML’s limitations and how it compares to and works with XML. We’ll examine the goals of XML as well as the rules for well-formed XML, and we’ll look at XHTML, the newest recommendation from the W3C.
What Is XML?
XML stands for Extensible Markup Language. This new language enables users to create documents that contain information about content that is more specific than ever before, adding a certain level of “intelligence.” Consider the following statement: The Web itself is becoming a kind of cyborg intelligence: human and machine, harnessed together to generate and manipulate information. If automatability is to be a human right, then machine assistance must eliminate the drudge work involved in exchanging and manipulating knowledge.…
Copyright ©2002 SYBEX, Inc., Alameda, CA
www.sybex.com
What Is XML?
345
This quotation is from the paper “The Evolution of Web Documents: The Ascent of XML” (www.cs.caltech.edu/~adam/papers/xml/ascent-ofxml.html; World Wide Web Journal, Special Issue on XML, Volume 2, Number 4, Fall 1997), in which authors Dan Connolly, Rohit Khare, and Adam Rifkin illuminate the potential of XML as a markup language that describes content in meaningful terms. XML was created to function transparently, providing machines with document information that will facilitate decision making at the machine level. XML is derived from the Standard Generalized Markup Language (SGML). SGML is called a metalanguage, which is a language for creating other languages. To understand XML, you should first have a basic understanding of what a markup language is, what a metalanguage is, how SGML spawned XML, and how XML differs from HTML.
What Markup Languages Do Markup languages are designed to tell computers how to process data. The term markup derives from early print publishers, who would “mark up” text by hand to indicate to the printer which font size to use where and in which weight, what form of alignment to use, and so forth. In other words, the earliest markup languages were dedicated to passing formatting instructions. Markup instructions are generally referred to as tags, and the process of marking up a document is sometimes called tagging. Early word processing programs required the user to perform manual tagging. Today, most tagging in programs happens transparently and usually takes place using a proprietary system. The different methods for tagging text made it difficult for people to exchange data with each other. With the advent of the Internet, it became more valuable and more imperative for authors to be able to exchange documents in a format that was easy to use yet powerful and aesthetically acceptable. Markup specifically designed to affect the appearance of a document is commonly called procedural markup because it tells the computer how to render the text. However, organizations that process huge numbers of documents, such as government and bureaucratic entities, quickly found that it was more important to know what the data represented rather than how it looked. Markup was then created to describe the content of the page. This type of markup is called descriptive or logical markup. The following is
Copyright ©2002 SYBEX, Inc., Alameda, CA
www.sybex.com
346
Chapter 13
Extensible Markup Language (XML)
HTML procedural markup for tagging the word Summary to appear in bold print: Summary In logical or descriptive markup, it makes more sense to designate the word Summary as a section header. The following is HTML logical markup for tagging the word Summary as a subheading: Summary
SGML: A Short History In the late 1960s, as computers were starting to be widely used in certain arenas, a group called the Graphic Communications Association (GCA) created a layout language called GenCode. GenCode was designed to provide a standard language for specifying formatting information so that printed documents would look the same regardless of the hardware used. In 1969, Charles Goldfarb led a group of people at IBM who built upon the GenCode idea and created what became known as the General Markup Language (GML). Whereas GenCode was primarily a procedural markup language, GML aimed to define not only the appearance but to some degree the structure of the data. Nearly 10 years after GML emerged, the American National Standards Institute (ANSI) established a working committee to build upon GML and create a broader standard. Goldfarb was asked to join this effort and has since become known as the “Father of SGML,” which was the end product of ANSI efforts. The first draft of SGML was made public in 1980; the final version of the standard emerged in 1986. Since that time, the language has been enhanced as needed. For example, in 1988 a version of SGML that was designed specifically for military applications (MIL-M-28001) was created. Other additions to the language have been incorporated over the years, and now some people feel that SGML suffers from complexity bloat.
XML: A Subset of SGML, Not HTML Many people think XML is an addition of tags to HTML. This assumption is incorrect. The following was noted in the second annual XML conference
Copyright ©2002 SYBEX, Inc., Alameda, CA
www.sybex.com
HTML Goals
347
held in 1998 in Seattle, Washington:
HTML is display.
XML is content.
XML is not HTML.
Unlike HTML, XML is not an application of SGML; it’s a subset of SGML. XML is SGML made simpler and more accessible; it is sometimes referred to as “SGML Lite.” As such, XML qualifies as a metalanguage and can be used to write other languages. XML offers users the ability to define their own set of markup tags—to write their own version of HTML, so to speak.
HTML Goals
I
n 1989, Tim Berners-Lee wanted to find a language that would allow people from all over the world to create documents that could be read by a universal client, a product more commonly called the web browser. From that idea, HTML was born. Berners-Lee thought that SGML provided the most promising model, but he knew that the difficulty of mastering the language would hamper the development and sharing of information. He created a very simple, efficient language for marking up text. HTML is based on SGML. HTML is not extensible. There is a finite set of HTML elements, which are entered into pages as tags. HTML was originally created to define structure, not formatting. The original specification had a limited set of markup elements that designated text as a header, a paragraph, a list item, and other simple units. In its earliest form, HTML provided an incredibly simple and effective way for people to generate clear, readable documents. Remember that the Internet was originally made popular by academics who wanted to share research across great distances. You can understand why the first version of HTML was mostly focused on creating clear, simple pages rather than flashy, interactive home pages for movie studios and other
Copyright ©2002 SYBEX, Inc., Alameda, CA
www.sybex.com
348
Chapter 13
Extensible Markup Language (XML)
corporations. The following code represents a simple page marked up with HTML 1 tags: <TITLE>Body Surfing Body Surfing
This document is designed to teach you how to enjoy the ride of your life. You will find many good tips and tricks here. Read, and then go out and try this on your own!
Finding the Wave
The following are the key elements to look for in a wave: Notice that the markup is straightforward. A title for the document is identified by opening and closing <TITLE> tags. The main heading is marked as a heading level 1 by the tag. The tag marks the beginning of a subheading. Plain text is not marked up, but when a paragraph break is needed, the
tag is used to start a new paragraph. The