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 #60. Mix Content with XML Namespaces

An XML document can combine content of several different types.

The W3C (http://www.w3.org) XML Namespaces specification allows document syntax from several different types of XML documents to exist in one file. Firefox's Gecko rendering engine can display some documents that are of mixed type, but not all. This hack shows combinations that are both feasible and useful.

Play with XML Namespace Syntax

Here is the syntax for namespaces. An XML document has a default namespace, which is specified by a URL. The namespace URL is different than the document definition. This XHTML 1.0 fragment shows both:

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC
  "-//W3C//DTD XHTML 1.0 Strict//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
>
<html xmlns="http://www.w3.org/1999/xhtml">
...

The URL in the DOCTYPE declaration says where the definition of this document is located. That's a hint to Firefox that explains what resources to use when displaying the document. The URL in the <html> tag says which URL belongs to the default namespace. That's a hint to Firefox that explains how to allocate tags found in the file to the right standard.

Here are the only namespaces that Firefox has special display support for:

http://www.w3.org/1999/xhtml
http://www.w3.org/1998/Math/MathML
http://www.w3.org/2000/svg
http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul

These namespaces are XHTML 1.0, MathML 1.0, SVG 1.0, and Mozilla's XUL, respectively. Namespace-less ...

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