O'Reilly logo

Firefox Hacks by Nigel McFarlane

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #73. Generate XUL Using PHP Libraries

There's more than one way to create XUL content. Here's how to do so using PHP libraries.

We have already seen a number of ways to create XUL content for Mozilla [Hack #72] . The first and the simplest is just manually written, static XML. The second is to use XUL templates and XML-RDF to generate XUL based on assertions in RDF. The third is to use JavaScript in conjunction with the Mozilla Document Object Model (DOM) and create the XUL elements programmatically.

The fourth and final way is the subject of this hack: to generate XUL procedurally on a remote host and stream the content like a web page into Mozilla. This hack uses PHP to create the XUL content.

Finding PEAR Libraries for XUL

PEAR (http://pear.php.net) is a collection of reusable PHP libraries. One such PEAR library is XML_XUL, which allows remote generation of Mozilla's XUL using PHP's XML DOM. You can find the PHP XUL Libraries at http://pear.php.net/package/XML_XUL

While it is great to see XUL getting such widespread support, generating XUL in this fashion is a big design choice. In reality, all the programmer is doing is creating an extra unnecessary layer on top of XUL, which blurs the distinction between the XUL user interface (UI) and its data. If you view your network-enabled service as a data service (for example, a stock market feed), don't do this. If you view your network-enabled service as remote application delivery or as a media-oriented content-delivery solution ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required