Chapter 4. Namespaces
Namespaces have two purposes in XML:
To distinguish between elements and attributes from different vocabularies with different meanings that happen to share the same name
To group all the related elements and attributes from a single XML application together so that software can easily recognize them
The first purpose is easier to explain and grasp, but the second purpose is more important in practice.
Namespaces are implemented by attaching a prefix to each element
and attribute. Each prefix is mapped to a URI by an xmlns:prefix
attribute. Default URIs can also be provided for elements that don’t
have a prefix. Default namespaces are declared by xmlns attributes. Elements and attributes that are attached to
the same URI are in the same namespace. Elements from many XML
applications are identified by standard URIs.
In an XML 1.1 document, an Internationalized Resource Identifier (IRI) can be used instead of a URI. An IRI is just like a URI except it can contain non-ASCII characters such as é and π. In practice, parsers don’t check that namespace names are legal URIs in XML 1.0, so the distinction is mostly academic.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access