Java Reference
In-Depth Information
As you can see, the namespace can resolve conflicting names. Many intricacies
make mastering namespaces seem like black magic, but if you can learn to do
so, you can unleash significant power. At design time, you must decide
whether to use exposed versus hidden namespaces, how to set the default
namespace, and how to determine the number of namespaces. Such intricate
issues are beyond the scope of this topic. For additional information, consult
the “ XML Schema: Best Practices” page at http: // /
Our example hardwires the schema location to the type. In the next sec-
tion, we'll learn how to make the association between type and the implemen-
tation for a type more dynamic.
Rigid constructs
Some of the time, we want tight control over an XML definition and how it
can be extended. The rest of the time, we should strive for flexibility. Now,
we'll look at practices that can limit the flexibility in an XML document. None
of these practices are always inherently bad, but they do have the negative
consequence of limiting flexibility.
Hardwiring components to a namespace
Choosing a namespace for a schema unnecessarily binds the schema to that
namespace early in the process. When we do so, we're also adopting the
semantics of the namespace to our schema. We can delay the binding process
by creating compact nameless schemas and letting the application that uses the
schema map a better namespace onto the schema. Through this delayed bind-
ing, we can choose the best namespace at the application level, thus control-
ling the target application semantics and ensuring flexibility.
Hardwiring a type reference to a type implementation
When we define a type in one document and rigidly fix the type within an
import, we're constraining the type implementation to the imported specifica-
tion. This implementation is probably one of the most common. The follow-
ing line binds a type to a type implementation:
<xsd:import namespace=""
schemalocation="frame.xsd" />
<xsd:element name="frame" type="frame:frameType"/>
We can delay the binding between type and schema location (and thus the
type implementation). We don't have to specify the schema location; it's an
optional parameter. Instead, when we create an instance of this document, we
Search WWH ::

Custom Search