Home arrow XML arrow Page 3 - An Introduction to XUL Part 1

Follow the rules - XML

Would you like to learn how to make rich user interfaces with nothing more complicated than a text editor? Welcome to XUL, a subset of XML used to describe user interfaces. This article will get you started.

  1. An Introduction to XUL Part 1
  2. Getting started
  3. Follow the rules
  4. Adding buttons
By: Dan Wellman
Rating: starstarstarstarstar / 22
May 23, 2005

print this article



As XUL is an XML technology, the usual XML syntax rules apply; documents must begin with the XML declaration, all elements should be closed correctly, nested correctly, and so forth. All code, with the exception of string values, should be in lowercase, and the XUL namespace must be declared in the root element. Those used to XML will find the syntax of XUL very easy to get the hang of; in fact, it will sometimes seem intuitive.

As stated above, you can create a XUL window using just a Notepad style application, so in Notepad, or the text editor of your choice, create your first XUL interface window by typing the following code:

<?xml version="1.0"?>
  id="MyFirstWindow" title="My First XUL Window!" width="500"   height="300" screenX="50" screenY="100"   xmlns="

All XUL documents should begin with the XML declaration, and all XUL elements will need to be contained within the window element, which must include the XUL namespace attribute shown above. As with any XML element, there are certain attributes that you can make use of to modify the appearance of the element in question. Here, the code specifies the id (for scripting purposes), the text that appears on the title bar, the dimensions, and where it should appear on screen.

Now save the file as myFirstWindow.xul, and remember to change the "save as" drop-down to all applications or you’ll just end up with a file called myFirstWindow.xul.txt which won’t do anything interesting at all, even if opened from within Mozilla. Issue the execution command on the command line (Mozilla –chrome file://C:/XULApps/myFirstWindow.xul), and a very plain window should appear. You can make this look a little bit like Mozilla by including the stylesheet reference as follows above the opening window tag:

<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

Which at this early stage just gives you a kind of grayish background.
The ref to the CSS file above contains the chrome directory, which forms part of the chrome architecture. The chrome architecture refers to the elements of Mozilla that make up how the interface looks.  Other applications that make use of XUL will also make use of a chrome directory for storing XUL, CSS and RDF files, and when making larger XUL applications, a directory structure that includes a chrome folder is something that you will need to make use of as well. RDF, by the way, stands for Resource Description Framework, and is another W3C recommended XML technology used to describe metadata (information about information).

>>> More XML Articles          >>> More By Dan Wellman

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Google Docs and Xpath Data Functions
- Flex Array Collection Sort and Filtering
- The Flex Tree Control
- Flex List Controls
- Working with Flex and Datagrids
- How to Set Up Podcasting and Vodcasting
- Creating an RSS Reader Application
- Building an RSS File
- An Introduction to XUL Part 6
- An Introduction to XUL Part 5
- An Introduction to XUL Part 4
- An Introduction to XUL Part 3
- An Introduction to XUL Part 2
- An Introduction to XUL Part 1
- XML Matters: Practical XML Data Design and M...

Developer Shed Affiliates


Dev Shed Tutorial Topics: