Apache XML Namespace Support

The XML Namespace API enables markup to be processed at the server (or proxy) according to namespace. Thus, for example, formats such as XHTML or SVG to be delivered to the user may be mixed with processing instructions such as SQL queries, higher-level structure and metadata (e.g. mod_annot), processing instructions such as SSI or ESI, and application-specific markup such as that used by Microsoft Office.

The Basic API

The basic approach is that any module may register itself as a handler for a namespace by implementing a struct xmlns and registering it as a handler for xmlns:

	#include "xmlns.h"

	  static const char* MYNAMESPACE = "http://example.com/my-namespace#" ;

	  static xmlns my_namespace = {
	  } ;
	  ap_register_provider(pool, "xmlns", MYNAMESPACE, version, &my_namespace) ;

The xmlns struct comprises a subset of SAX2 callbacks, which will be called at every event in the namespace we registered for. In addition, a namespace handler may register to process comments: this is an extension designed for the benefit of hybrid namespace/comment processors such as ESI, and also enables SSI to be implemented easily both as a namespace and a comment processor.

Consumers and Providers

Namespace processing is activated by a SAX2 parser that consumes the xmlns API. WebÞing currently provides two consumers: a minimal processor mod_xmlns, and the universal markup manipulation module mod_publisher. A provider that implements the API provided in xmlns.h is guaranteed to be both source- and binary- compatible with either consumer implementation. A namespace module MUST NOT rely on implementation details other than those exposed in the API.


The API itself is documented in xmlns.h. A tutorial article on implementing a namespace provider is in preparation, and one on implementing a consumer may follow.

Namespace Projects

A few existing projects from WebÞing that use the API are:

XHTML: Appendix C and SSI

mod_xhtml was originally written as a trivial demonstrator of the API, transforming XHTML to ensure it conforms with the W3C Appendix C guidelines for serving as text/html. More recently it has been updated to support Serverside Includes, both in traditional comment format and equivalently as a separate namespace.

Annotations Framework

The ApacheTutor site needed a framework to manage more document structure information and metadata than is possible within XHTML. By incorporating this as XML in a namespace-driven framework, we are able to implement what would traditionally be a database-driven framework, yet view documents lightning-fast without the overhead of database lookup.

SQL API for namespace applications

mod_sql implements a namespace to execute SQL queries (and display results where applicable) within a page. mod_sql is a Consumer of the Apache DBD API, so it can work cleanly with whatever database is available to a server. To complete the web applications environment, it can accept input from a browser via mod_form.

Rewriting Links

mod_proxy_html has been WebÞing's most popular module throughout 2004. A similar module for XML document types, mod_proxy_xml, was written in October. By using the namespace API rather than implementing its own parser separately, mod_proxy_xml was able to save a lot of work (it is 70% smaller than mod_proxy_html), and can also coexist with other XML processing at no additional overhead.

Edge Side Includes

A namespace parser for http://www.edge-delivery.org/esi/1.0 was implemented for an early draft version of mod_xmlns. It is not compatible with the current API, but can be updated if there is interest.