Download The Java™ Web Services Tutorial

Transcript
REFERENCING A NAMESPACE
researched. They’re not seeing a lot of action at the moment, but that could
change in the future.)
Referencing a Namespace
When a document uses an element name that exists in only one of the.DTDs or
schemas it references, the name does not need to be qualified. But when an element name that has multiple definitions is used, some sort of qualification is a
necessity.
Note: In point of fact, an element name is always qualified by it’s default
namespace, as defined by name of the DTD file it resides in. As long as there as is
only one definition for the name, the qualification is implicit.
You qualify a reference to an element name by specifying the xmlns attribute, as
shown here:
<title xmlns="http://www.example.com/slideshow">
Overview
</title>
The specified namespace applies to that element, and to any elements contained
within it.
Defining a Namespace Prefix
When you only need one namespace reference, it’s not such a big deal. But when
you need to make the same reference several times, adding xmlns attributes
becomes unwieldy. It also makes it harder to change the name of the namespace
at a later date.
The alternative is to define a namespace prefix, which as simple as specifying
xmlns, a colon (:) and the prefix name before the attribute value, as shown here:
<SL:slideshow xmlns:SL='http:/www.example.com/slideshow'
...>
...
</SL:slideshow>
279