Java Reference
In-Depth Information
variable names. If we accept the premise that control of an XML schema has
some value, we should strive for designs that don't force us to prepend
variable names with proprietary extensions. A namespace is the XML schema
extension designed to handle this problem.
In listing 7.6, we first create a namespace. Next, we declare namespaces for
both of our reused schemas ( b ). Within our composite document ( bike.xsd ),
we can then import the namespaces ( c ), and use the types within to create a
type called bike . Let's assume that both our frame and component companies
use the identifier classification . Usually, these types within the comp.xsd
and frame.xsd would collide, but the namespace will protect us ( d ).
Listing 7.6
XML namespaces help resolve naming collisions.
<xsd:schema xmlns:xsd="our-URL"
targetNamespace="http://www.bikespace.org"
xmlns:frame="url-for-frame-namespace"
xmlns:component="url-for-component-namespace"
xmlns:wheel="url-for-wheel-namespace"
xmlns:fork="url-for-fork-namespace" />
B Defining
the
namespace
C Importing the
namespace
<xsd:import namespace="url-for-frame-namespace"
schemalocation="frame.xsd" />
<xsd:import namespace="url-for-component-namespace"
schemalocation="comp.xsd" />
<xsd:import namespace="url-for-fork-namespace"
schemalocation="fork.xsd" />
<xsd:import namespace="url-for-wheel-namespace"
schemalocation="wheel.xsd" />
<xsd:element name="bike">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="frame"
type="frame:frameType"/>
<xsd:element name="component"
type="component:componentType"/>
<xsd:element name="fork"
type="fork:forkType"/>
<xsd:element name="wheel"
type="wheel:wheelType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
The types can
share names
without
colliding
d
</xsd:schema>
Search WWH ::




Custom Search