Using namespaces

Namespace declaration

Namespaces are defined using attributes. The attribute name 'xmlns' is used to declare a namespace. The value of this attribute is a (complete, not relative) reference to the namespace concerned. For example:

<html xmlns="http://www.w3.org/TR/REC-html40">
  ...<p>An HTML paragraph.</p>...
</html>

However, this attribute is also used to supply the replacement prefix to be used in element and attribute names. This is done by extending the name to include the prefix. The prefix is separated from the 'xmlns' part of the name using a colon. This can be confusing at first, because the namespace prefix is defined by the attribute name suffix. In the following example, the HTML 4.0 namespace is referenced, and given ...

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.