Java Reference
In-Depth Information
</sketcher:circle>
</sketcher:sketch>
Each reference to the element name is qualified by the namespace prefix sketcher . A reference in the
same document to a <circle> element that is defined within another namespace can be qualified by the
prefix specified in the declaration for that namespace. By qualifying each element name by its namespace
prefix, you avoid any possibility of ambiguity.
A namespace has scope — a region of an XML document over which the namespace declaration is vis-
ible. The scope of a namespace is the content of the element within which it is declared, plus all direct or
indirect child elements. The preceding namespace declaration applies to the <sketch> element and all the
elements within it. If you declare a namespace in the root element for a document, its scope is the entire
document.
You can declare a namespace without specifying a prefix. This namespace then becomes the default
namespace in effect for this element, and its content and unqualified element names are assumed to belong
to this namespace. Here's an example:
<sketch xmlns="http://www.wrox.com/dtds/sketches">
There is no namespace prefix specified, so the colon following xmlns is omitted. This namespace be-
comes the default, so you can use element and attribute names from this namespace without qualification
and they are all implicitly within the default namespace. For example:
<sketch xmlns="http://www.wrox.com/dtds/sketches">
<circle angle="0" diameter="30">
<color R="150" G="250" B="100"/>
<position x="30" y="50"/>
<bounds x="30" y="50"
width="32" height="32">
</bounds>
</circle>
</sketch>
This markup is a lot less cluttered than the earlier version that used qualified names, which makes it much
easier to read. It is therefore advantageous to declare the namespace that you use most extensively in a doc-
ument as the default.
You can declare several namespaces within a single element. Here's an example of a default namespace
in use with another namespace:
<sketch xmlns="http://www.wrox.com/dtds/sketches"
xmlns:print="http://www.wrox.com/dtds/printed">
<circle angle="0" diameter="30">
<color R="150" G="250" B="100"/>
<position x="30" y="50"/>
<bounds x="30" y="50"
width="32" height="32">
</bounds>
</circle>
<print:circle print:lineweight="3" print:linestyle="dashed"/>
</sketch>
Search WWH ::




Custom Search