How to Create a Template in XUL

How to Create a Template in XUL thumbnail
XUL Templates can be used to create applications on the Mozilla platform.

XUL, or XML User Interface Language, is a language that can be used to create applications and user interfaces for the Mozilla platform. XUL allows developers to create graphical user interfaces that mix technologies such as XML, HTML and CSS and can run either connected or disconnected from the Internet. XUL templates allow developers to embed data in XUL documents by defining a set of rules that are used to build applications that take advantage of remote data sources, separating data from the application itself.

Things You'll Need

  • A Web browser based on the Gecko layout engine, such as Firefox or Camino
  • Text editor
Show More

Instructions

  1. How to Create a Template in XUL

    • 1

      Open a text editor and create a new file called characters.xml. Type some XML in the file that defines a root element <characters> with five <character> child elements:

      <?xml version="1.0"?>

      <characters>

      <character></character>

      <character></character>

      <character></character>

      <character></character>

      <character></character>

      </characters>

      The <characters> XML will be used to populate a list defined in the XUL template. Save characters.xml.

    • 2

      Edit characters.xml and add a name attribute and an animal attribute to each of the character XML elements, placing the attribute values inside double quotes:

      <?xml version="1.0">

      <characters>

      <character name="Mickey" animal="mouse"></character>

      <character name="Minnie" animal= "mouse"></character>

      <character name="Pluto" animal="dog"></character>

      <character name="Donald" animal="duck"></character>

      <character name="Daisy" animal="duck"></character>

      </characters>

      Save and close characters.xml.

    • 3

      Use a text editor to create a file that contains the XUL template. Type the XML version header and a <window> element inside the file and add a default xmlns name space to the <window> element:

      <?xml version="1.0"?>

      <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

      </window>

      Save the file as characters.xul.

    • 4

      Continue editing characters.xul and add a <listbox> element to the file, placing it between the <window> and </window> element tags. Use a data source attribute to indicate that the list box should get its data from characters.xml. Set the ref attribute to "*" (dummy value) and the querytype attribute to "xml" to tell the template builder that XML syntax will be used. Close the </listbox> element:

      <?xml version="1.0"?>

      <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

      <listbox datasources="characters.xml" ref="*" querytype="xml">

      </listbox>

      </window>

      Save characters.xul.

    • 5

      Continue editing characters.xul and add a <template> element to the file, placing it between the <listbox> and </listbox> element tags. Add a <query> element between the <template> and </template> element tags, using the expr attribute to retrieve the character elements from the characters.xml file. Close the query tag:

      <?xml version="1.0"?>

      <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

      <listbox datasources="characters.xml" ref="*" querytype="xml">

      <template>

      <query expr="character"></query>

      </template>

      </listbox>

      </window>

      Save characters.xul.

    • 6

      Continue editing characters.xul and add an <action> element to the file, placing it after the <query> element. The <action> element contents will define the content that will be generated for each query result:

      <?xml version="1.0"?>

      <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

      <listbox datasources="people.xml" ref="*" querytype="xml">

      <template>

      <query expr="character"></query>

      <action>

      </action>

      </template>

      </listbox>

      </window>

      Save characters.xul.

    • 7

      Continue editing characters.xul and add two <listitem> elements between the <action> and </action> element tags. Use the label attribute to indicate that the first list item should use the "name" attribute from the character elements in characters.xml. Use the label attribute to indicate that the second list item should use the "animal" attribute from the character elements in characters.xml. Add a uri attribute to both list items, using the value "?", which is the default value for XML templates:

      <?xml version="1.0"?> <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

      <listbox datasources="people.xml" ref="*" querytype="xml">

      <template>

      <query expr="character"></query>

      <action>

      <listitem uri="?" label="?name"></listitem>

      <listitem uri="?" label="?animal"></listitem>

      </action>

      </template>

      </listbox>

      </window>

      Save and close characters.xul.

    • 8

      Use a Mozilla browser, such as Firefox, to open characters.xul. Verify that the contents of characters.xml are loaded into the list box defined in the xul template.

Tips & Warnings

  • XUL templates can retrieve data from non-XML based sources, such as RDF and databases. Use the source that is most appropriate for the application you are building.

  • XUL provides a rich variety of user interface components. Try using other XUL user interface objects to build more advanced applications.

  • Since XUL applications are platform-neutral, they can be ported to other Mozilla platforms. See the references section for information on building XUL applications.

  • When using XUL on a website, the server must be configured to send XUL files with the appropriate content type.

Related Searches:

References

Resources

  • Photo Credit stock image of aqua presentation template image by Ruslana Stovner from Fotolia.com

Comments

You May Also Like

  • How to Edit XML

    The XML file format is a decoded interface language that is commonly used for Microsoft Internet Explorer, programs, and file component formatting....

  • How do I Find a File Where Thunderbird Email Is Stored?

    Using the free Thunderbird email program, computer users can send and receive emails from a browser. The system has technology to satisfy...

  • How to Query an XSD

    XML Schema Definition (XSD) is developed by the World Wide Web Consortium for creating XML Schemas, which are a set of rules...

  • How to Create an XML Return File for Ajax

    With AJAX, you can create various projects that deal with JavaScript and XML because AJAX is exactly that: Asynchronous JavaScript and XML....

  • How to Write a Web Page Using XML

    The key to creating a Web page using XML is to understand that XML elements must be converted into HTML in order...

  • How to Create XML Document Using JDOM

    JDOM is an open source implementation of an XML document manipulation library for the Java programming language. JDOM is bundled with most...

  • List of XML Editors

    List of XML Editors. XML stands for EXtensible Markup Language and is designed to carry or transport data. XML has quickly become...

  • How to Create Multiple Directories in Linux

    Linux makes it easy for you to manipulate files and directories with a few steps, or even a single step. If you...

  • XML to XSL Conversion

    XML to XSL conversion refers to the transformation of XML data into a required output format using XSL, or "Extensible Stylesheet Language,"...

  • How to Set Up a Mail Merge Data Source in Word 2003

    After you set up a mail merge data source in Word 2003, you never again need to type the individual addresses on...

  • How to Find Out My Mayan Calendar Symbol

    The Mayan Zodiac is based off an ancient and complex calendar system created by the Mayan people more than 5,000 years ago...

  • XML Publisher Training

    XML Publisher is an Oracle application, also called Business Intelligence (BI) Publisher, which allows you to aggregate XML data into a document...

  • How to Read an XML File in Java Script

    XML (Extensible Markup Language) is the international standard for defining data descriptions to work on the Internet across varying operating systems and...

  • How to Read an XML File With PHP

    Extensible Markup Language (XML) allows you to organize information in a way that describes the information and is easy for computer programs...

  • How to Create an .Xml File

    XML stands for Extensible Markup Language. This form of computer programming transports and stores data as a text file but does not...

  • How to Make a Form in Excel

    Excel is a software program used for creating spreadsheets. These spreadsheets can be used to organize data and perform calculations. In organizations...

  • XML Database Schema Tutorial

    The XML Schema (or XSD) is the W3C-suggested language to define the structure and data types of an XML database. It replaces...

  • How to Call Environment Variables From Visual Basic

    Environment variables are saved settings for the operating system. For instance, a common environment variable is the location of the operating system...

  • How to Create a Mayan Calendar

    The Mayans used a 365 day calendar called Haab to keep watch on the year's cycle. The year is called the Vague...

Related Ads

Featured