- 97 -
Let’s take a closer look at what’s going on:
xmlns
:mama="http://mamazon.com/schema"
xmlns
:nab="http://NarnesAndBobel.com/book.dtd"
xmlns
:e_com_org="http://e_com_org.com/schema">
Our
root element is
Results
.
The xmlns keyword is part of the reserved vocabulary in XML used for declaring the
namespace prefix
(in this case mama, nab, and e_com_org) and the location (a UUID,
URN, URI, or URL) of the respective DTD or schema.
UUID, URN, and URI
All of these are ways of representing the complete address and route for locating a
file across electronic networks.
A UUID is a Universally Unique IDentifier. It is similar to a GUID (Globally Unique
IDentifier), which is used for identifying COM (Component Object Model) objects.
A URN is a Uniform Resource Name. It defined by the IETF (Internet Engineering
Task Force) as “resource identifiers with the specific
requirements for enabling
location independent identification of a resource, as well as longevity of reference.”
Simply put, they provide permanent, unique addresses for files over a network.
A URI is a Uniform Resource Identifier. The IETF defines a URI as a scheme that
allows resources to be uniquely named over time and space using Universally
Unique Identifiers (UUIDs). It consists of a series of characters.
The namespace prefix mama is used to distinguish every attribute and element whose
description (document type definition) comes from the
http://mamazon.com/schema
file.
The namespace prefix nab is used to distinguish every attribute
and element whose
description comes from the DTD file located at
http://NarnesAndBobel.com/book.dtd
.
Similarly, the prefix e_com_org is used to describe standard elements and attributes that
are defined by the mythical E-commerce Organization.
The xmlns: attribute’s value is the location of the DTD or schema. The parser goes to
those locations, reads through their definitions, and commits
them to memory so that
whenever an element or attribute bearing the namespace prefix appears in the Results
element, it is validated against the respective DTD or schema.
The region or
scope
where you can use elements and attributes of the types defined in
the given schemas and DTD is limited to the child elements and attributes of the Results
element. This is called scoping
the namespace. You could locally
scope the namespaces
by assigning the xmlns: keyword in each element, but the following is a much more
efficient way of doing this:
Here we’re using a book element whose definitions are described in the
http://mamazon.com/schema
file. When parsed to check for validity, the parser checks
this element against the type definitions expressed in the schema. Thus, the rest of the
book element’s structure has to look exactly like it would if it were working in isolation.
- 98 -
We’ve prefixed all the mama:book elements with the mama prefix to tell the parser that
each component used is to be validated against the Mamazon.com schema.
2.75
We’re trying to illustrate that it is possible to use components described across many
different schemas and DTDs. Here, we’ve made up a mythical electronic commerce
organization that globally defines standards for currency units. While the mama:price
element is subject to validation against Mamazon’s schema, its currency attribute is
subject to validation against the E-commerce Organization’s schema.
Also, we should clarify that we’re assuming that the mama schema has a provision for
allowing a currency attribute in it whose definition
comes from the E-commerce
Organization.
Here we’re using a book element whose definitions are described in the
http://NarnesAndBobel.com/book.dtd
file. When this element is parsed to check for
validity, the parser checks it against the type definitions expressed in that DTD. Thus, the
rest of the nab:book element’s structure—in this case its attributes—have to look exactly
as it would if it were working in isolation. We’ve prefixed all of the nab:book attributes with
the nab prefix to tell the parser that each component used is to be validated against the
NarnesAndBobel DTD.
You should buy the book from Mamazon.com
Wait a minute; these elements don’t have any prefixes! That’s fine. Remember that you
don’t
have
to validate everything. In this case, because this element is our own and we
have control over it, we decided not to validate it against anything. Our Result element is
not limited to only containing elements and attributes defined in the xmlns: attribute
values.