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.
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:
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:
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).