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

Content Elements - XML

Learn about XUL, a subset of XML used to describe user interfaces, that helps you to make rich user interfaces with nothing more complicated than a text editor. In the third part of this series covers layout and content elements.

TABLE OF CONTENTS:
  1. An Introduction to XUL Part 3
  2. Flex and Grids
  3. Groupbox, Stack and Deck
  4. Content Elements
By: Dan Wellman
Rating: starstarstarstarstar / 7
June 06, 2005

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

All I’ve talked about so far are elements; interface elements and layout elements.  What I haven’t mentioned yet are content elements.  We’ve seen buttons, labels, controls etc, but nothing in which to actually store content.  What that content actually is depends on what the application does, for a browser, such as Mozilla, the main content is HTML pages.  As XUL came around in order for Mozilla to actually be constructed, HTML pages are easily displayed using an iframe element.  To test this out fully, you’ll need a web page to display.  You could create one of your own, or to save yourself some time you could work with something that’s already out there.

What I did was to go to the Google homepage (because it has a relatively simple homepage but features many links and has some functionality) in a browser, and save the page as google.htm to my XUL directory.  Do whatever you want, but get an HTML file that at least has links to other pages on it.  Now, create a basic window (I mean add the opening and closing window element to a blank text file with the necessary namespace) with nothing in it except the following line of code:

<iframe src="google.htm" flex="1"/>     

Note that the attribute must be included, or the page will not open within the iframe.  Now, save it as iframe.xul or similar and then execute it with the command line.  Your window should appear with the Google homepage loaded in it.  The links should work and you can even do actual searches with it.  You’ve just created a browser, with just a couple of lines of code!  If your window is smaller than the size of the page you’ve selected for this example, Mozilla will even include working scrollbars for you, with no additional code.  You’re not restricted to displaying just web pages either, change the src attribute of the iframe to one of the XUL files you’ve already created and watch in awe as that is loaded just as easily.  It will even render simple text files, which you can prove by changing the src to a file ending in .txt.  The files that you’re opening should be located in the same directory as the iframe.xul file, or should include the full path to them if they’re not.

I feel it appropriate to mention at this point that true to its XML roots, XUL is also able to work with and process HTML tags and render them within its windows accordingly.  In order to use the tags that it supports you need to make sure that the XHTML namespace is imported.  This requires the addition of the namespace to the opening window tag, and an HTML prefix preceding each HTML element you wish to use.  Create the following file for confirmation of this:

<?xml version="1.0"?>
<window
  id="html"
  title="Render HTML"
  width="500"
  height="300"
  screenX="50"
  screenY="100"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/
  there.is.only.xul"
  xmlns:html="http://www.w3.org/1999/xhtml"> 

<html:div>
  This is HTML!
</html:div>
<html:ol>
  <html:li>This is an html list item!</html:li>
  <html:li>So is this!</html:li>
</html:ol>

</window>

So you see, there are several very basic ways to include content within your XUL files.  The next article introduces RDF, and explains how more complex elements can be access via a chrome URL from within Mozilla to give added functionality and power to your XUL applications.



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

XML ARTICLES

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