Creating Applications with Mozilla >> 2. Getting Started >> 2.2. Basic XUL Concepts

You have already seen many of XUL's basic features at work. When you load the example in the previous example, the browser identifies it as a XUL file, parses the data, creates a new window and draws the button widget, and executes the function you've defined when the button is clicked.

These activities are part of the basic and often transparent interaction between your application files and Mozilla. However, the format of your XUL files, their syntax and namespace, the XUL layout, and the windowing system are all basic to successful XUL programming.[@more@]


2.2 基本XUL概念
你已经看到了XUL的基本功能是如何工作的了。当你再上一个例子中加载文件的时候,浏览器识别出这是一个XUL文件之后,就解析了数据,创建了一个新窗口,并画了一个按钮组件,并且在按钮被点击以后执行了你指定的函数。

这些行为都是基本功能的一部分,提供了你和浏览器之间透明的交互作用。但是,xul文件的格式,语法以及名称空间,xul布局元素以及这个窗口系统都是成功的xul编程的基础。

2.2.1. The XUL File Format

A XUL file is a simple text file that contains proper XML syntax and has a .xul file extension. Mozilla expects to draw UI widgets when it encounters a file with a .xul extension or when it encounters the XUL namespace in other markup files that it recognizes, including HTML and XML.

The MIME type registered for XUL files is application/vnd.mozilla.xul+xml. When editing and using XUL files locally, you shouldn't need to worry about setting this on your computer; however, sometimes you may need to set the MIME type, such as when you host XUL files on a server. Chapter 12 provides additional information about how you can set the correct file type for your system.

2.2.1 xul文件格式

一个xul文件只是一个简单的包含了正确的xml语法的后缀为xul的文本文件。当Mozilla碰到一个xul文件或者在其他标记式文件中碰到xul名称空间下的元素时,他会尝试去描绘一个用户界面组建,这里所说的标记式文件包括xml和html。

xul文件的MIME类型是application/vnd.mozilla.xul+xml。当在本地编辑和使用xul文件时,无需设置mime类型。但是有时候你会需要设置mime类型,比如把xul文件放在服务器上的时候。第十二章具体给出了如何在你的系统上正确设置xul的mime类型。

2.2.2. Conventions

XUL has to follow certain conventions (as does XHTML or any other XML-based file) in order to be valid. Mozilla generates an error when it encounters an invalid XUL file.

The first thing required in a XUL document is the XML declaration.



Any comments used to introduce your file can begin on the line after the declaration. Comments in XUL follow the same format used in HTML and XML, delimited by

你可能感兴趣的:(Creating Applications with Mozilla >> 2. Getting Started >> 2.2. Basic XUL Concepts)