XUL Is XML
Simplicity is a chief attraction of XML. When a suitable set of tags are available for a given problem domain, solutions in that domain can be expressed very neatly. For example, in the Structured Vector Graphics (SVG) XML application, a programmer can specify a circle simply with the <circle> tag.
XUL provides the same simplicity for GUIs: To create a scrollbar, use <scrollbar>. XUL was invented by Netscape and now is stewarded by the Mozilla Foundation. XUL is not a standard of the World Wide Web Consortium (W3C), but it assumes some W3C standards in its design. All XUL documents, for instance, are valid XML and support XML Namespace, DTD, and CSS2 syntax, as well as JavaScript. The XUL tag set is a de facto standard that has grown organically out of the practical needs of real software development projects. Just like HTML, XUL documents can be downloaded across the Internet and displayed locally. They can also be installed locally if required.
XUL doesn't have a URL that contains a definition of all the existing tagsthis fake URL is used instead:
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<window> is XUL's equivalent of HTML's <html> tag.
Before XML, expressing a software GUI required either a "canned" approach, in which a GUI design tool does all the work for you, or a heap of code written in some programming language. XUL uses neither of these strategies. Instead, each widget in the GUI is declared with one or more XUL tags, a strategy identical to that of HTML. For GUIs, this is an efficient and groundbreaking way to do software development. XUL is also designed so the same code will work across all platforms. Thus, your XUL document will display correctly on Microsoft Windows, Macintosh, and Linux.
The Mozilla platform and products derived from it, such as AOL for the Macintosh, Oeone's HomeBase, and Netscape, can all display XUL content. The platform can do this directly, without the use of any additional application. For example, Figures 1 and 2 show an ordinary XHTML page displayed first inside a Mozilla browser window (Figure 1), and secondly all by itself (Figure 2).
Figure 1 XHTML page displayed in a browser.
Figure 2 XHTML page displayed in a raw Mozilla window.
The second window displays a pure XHTML document; the first window is a normal browser window that consists of XUL plus the displayed XHTML. The browser menus, scrollbars, and buttons are made up of one or more XUL documents. Those buttons don't come from compiled code, and they're not somehow "special." They're just XUL tags made visible.
To display an XHTML, XUL, or XML document by itself, just use Mozilla's -chrome command-line option. For example, on Microsoft Windows, try this from the directory in which Mozilla is installed:
mozilla -chrome "http://www.yahoo.com/index.html"
The -chrome option leaves out the standard XUL content that provides the browser part of every browser window. Such a window can also be created from JavaScript if this call is placed inside a document that has some security restrictions removed:
window.open(URL, "_blank", "chrome=true");
Instead of leaving the XUL out, you can leave the XHTML out. A displayed window is then pure XUL, with no HTML. That window can be the basis of a whole application GUI, or of a humble dialog box. When you do that, you're stepping away from the HTML-centric style that lies behind most current web-based application development. For example, the Bookmark Manager window is written entirely in XUL (see Figure 3).
Figure 3 Mozilla's Bookmark Manager is written in XUL.
No 3GL code is required, although a drop of scripting goes a long way. This kind of window lets you break into the world of real application development. Time-efficient web-based skills can be applied to the world of real applicationsyou don't have to learn C++ or even Visual Basic. It's all XML in the end.