<< Chapter < Page | Chapter >> Page > |
XML allows you to
create documents in custom markup languages. But what if youwant to combine markup from multiple languages in the same
document? What if there are one or more tags that exist in bothlanguages, but with different meanings? You could, for example, have
a
<table>
tag in HTML and one
in a language describing office furniture as well. How do youuse these tags unambiguously, without losing functionality?
The solution is to use an extension to XML called
namespaces (See the W3C's recommendation,
Namespaces in
XML ). A namespace associates a unique global identifier
(usually a URI) with a particular set of tags and their usagerules. To declare a namespace for a particular tag, set the
xmlns
attribute to the value of the unique
identifier.
You can also define a
namespace prefix for use in
your document. To do this, use a modified version of the
xmlns
attribute. For example, you would
use the attribute
xmlns:foo="http://somewhere.org/foo"
to
associate the prefix
foo
with the namespace
identifier
http://somewhere.org/foo
. You
can then indicate which tags come from that namespace by addingthe appropriate prefix to each tag. Thus, the
bar
tag in foo's namespace would be written
as
<foo:bar>
and
</foo:bar>
.
When you use the default namespace any children of that tag lacking an explicit prefix will be assumed to have come from thesame namespace. This allows you to define a default namespace for all of the children of a tag. This is especially usefulwhen used on the root node , which is the outermost tag in a document.
For CNXML 0.6 there is only one schema. The document tag will contain the namespace for all available languages and will look like this:
<document xmlns="http://cnx.rice.edu/cnxml"
xmlns:md="http://cnx.rice.edu/mdml/0.4"xmlns:bib="http://bibtexml.sf.net/"
xmlns:m="http://www.w3.org/1998/Math/MathML"xmlns:q="http://cnx.rice.edu/qml/1.0"
id="new"cnxml-version="0.6"
module-id="new">
Notification Switch
Would you like to follow the 'Connexions tutorial and reference (中文指導及參考 - chinese)' conversation and receive update notifications?