XML technologies / XML Schema / Controlling namespaces / Two namespace challenges for schema languages
(Excerpt from “XML Schema” by Eric van der Vlist)
Namespace prefixes are only local abbreviations for URI references identifying the actual namespaces. Namespace-aware applications should regard the following documents as strictly equivalent:
<?xml version="1.0"?>
<library xmlns="http://dyomedea.com/ns/library">
<book id="b3810518883">
<title>
Auf den Hund gekommen
</title>
<authors>
<person id="CMS">
<name>
Charles M. Schulz
</name>
</person>
</authors>
</book>
</library>Above, namespace "http://dyomedea.com/ns/library" is the default, applying to every element. Next is an equivalent document with a different appearance:
<?xml version="1.0"?>
<!-- Namensraum: http://dyomedea.com/ns/library -->
<lib:library xmlns:lib="http://dyomedea.com/ns/library">
<lib:book id="b3810518883">
<lib:title>
Auf den Hund gekommen
</lib:title
<lib:authors>
<lib:person id="CMS">
<lib:name>
Charles M. Schulz
</lib:name>
</lib:person>
</lib:authors>
</lib:book>
</lib:library>Namespace "http://dyomedea.com/ns/library" is mapped to the prefix lib, used for every element. Next, another equivalent document uses a different prefix.
<?xml version="1.0"?>
<!-- Namensraum: http://dyomedea.com/ns/library -->
<l:library xmlns:l="http://dyomedea.com/ns/library">
<l:book id="b3810518883">
<l:title>
Auf den Hund gekommen
</l:title>
<l:authors>
<l:person id="CMS">
<l:name>
Charles M. Schulz
</l:name>
</l:person>
</l:authors>
</l:book>
</l:library>Namespace "http://dyomedea.com/ns/library" is mapped to prefix l, used for every element. Finally, we mix these approaches in one still-equivalent document:
<?xml version="1.0"?>
<!-- Namensraum: http://dyomedea.com/ns/library -->
<l:library xmlns:l="http://dyomedea.com/ns/library">
<l:book id="b3810518883">
<l:title>
Auf den Hund gekommen
</l:title>
<l:authors>
<l:person id="CMS">
<l:name>
Charles M. Schulz
</l:name>
</l:person>
</l:authors>
</l:book>
</l:library>The same namespace is defined and used as l, as lib and even as default namespace, depending on position. This extreme example is not recommended, but complies with the namespace recommendation and is strictly equivalent to the previous ones.
DTDs do not understand namespaces. Since a colon (:) is permitted in XML names, lib:person, l:person and person are three distinct valid names for a DTD. It also treats namespace declaration attributes (xmlns, xmlns:l, xmlns:lib) as ordinary attributes requiring declarations.
Namespace-using XML is well-formed XML 1.0, so a DTD can describe it. However, permitted prefixes and declaration locations must be fixed. This is acceptable only when document authoring can be controlled or precisely specified.
The larger second problem is design. As XML links applications, modular vocabularies coexisting within one element become increasingly important. Namespaces enable this, but often require open vocabularies with places for external elements and attributes without breaking applications.
Suppose marketing wants to add binding and page-count information to a book. If only marketing needs it and existing applications must be unaffected, a clever solution creates a new namespace:
<?xml version="1.0"?>
<!-- Namensraum: http://dyomedea.com/ns/library -->
<library xmlns="http://dyomedea.com/ns/library" xmlns:mkt="http://dyomedea.com/ns/library/mkt">
<book id="b3810518883">
<title>
Auf den Hund gekommen
</title>
<authors>
<person id="CMS">
<name>
Charles M. Schulz
</name>
</person>
</authors>
<mkt:cover>
Paperback
</mkt:cover>
<mkt:pages>
128
</mkt:pages>
</book>
</library>To keep the schema independent of marketing, we need a flexible opening: accept arbitrary marketing elements at the end of element book. If other applications use the vocabulary, arbitrary elements from any other namespace could be accepted at the end of element book.
Copyright © 2003 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “XML Schema” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de
back to top