Chapter 6
RDF and XUL Templates
"To build an apple pie
from scratch, you must first invent the universe." - Carl Sagan, Cosmos on
PBS, November 23, 1980
After having read the last few chapters, you have been introduced to the key concepts of XUL, and hopefully, your mind is full of ideas on the language's potential. If you use a XUL-capable web browser, you can change the browser's look and feel, and you can design and develop an application within the browser itself. Up to this point, all of the XUL examples that we have presented have been static. As we have been discussing XUL elements and building XUL files, we have been placing static data into the XUL files. This chapter will discuss approaches to including dynamic data sources into a XUL application using XUL templates with Resource Description Framework (RDF) data sources.
RDF stands for Resource Description Framework, which is a W3C standard for representing information, using XML as an interchange syntax.[i] RDF uses XML to exchange descriptions of Web resources in a portable way. Put simply, RDF is used to describe different resources and how they relate with one another. RDF emphasizes facilities to enable automated processing of Web resources in many interesting areas, such as cataloging search engines, promoting knowledge management between intelligent software agents, and expressing privacy policies for web sites and users on the Internet. An RDF model is often discussed as an "RDF graph", because it can be represented as a hierarchical tree-like structure.
The developers of the Mozilla XPToolkit use RDF and XUL together as the framework for the Application Object Model (AOM) of the Mozilla/Netscape browser. A XUL Template is the mechanism for creating dynamic user interfaces, and a template is directly related to one or more RDF data sources. Using this mechanism, XUL files can reference RDF data sources that represent constantly changing data instead of simply representing static information. XUL templates can aggregate multiple RDF datasources - that is, they can take data from different sources, both local and remote, and merge them together. A visual representation of bookmarks, mail items, or user preferences could be loaded into a user interface at run-time.
This chapter will present a brief overview of RDF data sources, and will give a comprehensive overview of building XUL templates for constructing dynamic data. In addition to these tutorials, we will demonstrate the main concepts with several examples. All of the code will be on our companion web site, http://www.xulbook.com/ in downloadable form.