Defaults

When every element has a prefix, the document can become difficult to read, and the extra characters certainly add to its size. Fortunately, the standard includes the concept of a default namespace.

Element defaults

Elements can belong to a default namespace, but this is done by declaring the namespace using an attribute named 'xmlns', with no suffix (as suggested earlier):

<document
						xmlns="file:///DTDs/document.dtd"
          xmlns:X="http://www.w3.org/TR/REC-html40">
  ...<description>...</description>...
  ...<X:td>An HTML table cell.</X:td>...
</document>

Overriding defaults

The default namespace can be changed at any point in the document hierarchy. This is an ideal technique when a sufficiently large XML fragment is embedded:

 <document xmlns="file:///DTDs/document.dtd" ...

Get XML Companion, The, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.