Complex types from another namespace

I am currently developing several schemas based on a common set of
complex data types. It seems reasonable to put the common types in one
namespace and the "end-user" schemas in several others. My problem is
that an instance document then has to be aware of which elements are
from which namespace. Is this a fundamental feature of XML Schema or am
I doing something wrong?

So for example, a simplified file for the common types might look like:

b.xsd:
======

<?xml version="1.0"?>
<xsd:schema
	targetNamespace="http://example.com/b.xsd"
	xmlns:xsd="http://www.w3.org/1999/XMLSchema"
	xmlns:b="http://example.com/b.xsd"
	elementFormDefault="qualified"
	attributeFormDefault="unqualified">

	<xsd:complexType name="AddressStructure">
		<xsd:element name="b:AddressLine" minOccurs="2" maxOccurs="5"
type="xsd:string"/>
		<xsd:element name="b:PostCode" minOccurs="0" maxOccurs="1"
type="xsd:string"/>
	</xsd:complexType>
</xsd:schema>


Any required types would then be imported into what I am calling the
"end-user" schema (the one that I want people to reference as the
default in instance documents):

a.xsd:
======

<?xml version="1.0"?>
<xsd:schema
	targetNamespace="http://example.com/a.xsd"
	xmlns:xsd="http://www.w3.org/1999/XMLSchema"
	xmlns:b="http://example.com/b.xsd"
	xmlns:a="http://example.com/a.xsd"
	elementFormDefault="qualified"
	attributeFormDefault="unqualified">

	<xsd:import namespace="http://example.com/b.xsd"/>

	<xsd:element name="Address" type="b:AddressStructure"/>
</xsd:schema>

I can then create a simple instance document like this:

simple.xml
==========

<?xml version="1.0" encoding="UTF-8"?>
<Address
	xmlns="http://www.boynings.co.uk/GovTalk/Schemas/a.xsd"
	xmlns:b="http://www.boynings.co.uk/GovTalk/Schemas/b.xsd">

	<b:AddressLine>1 Somestreet</b:AddressLine>
	<b:AddressLine>Sometown</b:AddressLine>
</Address>

Is there any way I can do this so that the instance document does not
need to be aware of which elements are from which namespace? I have just
worded that in a way that makes me think I am trying to defeat the
object of namespaces, but my aim is to ensure the uniqueness of names
through my end-user schemas, which have knowledge of what data types
they are using. I don't want the instance documents to have to know the
way the schema is constructed (i.e. whether it is defining the complex
types itself or importing them).

Regards

--
Paul Spencer

Received on Wednesday, 19 July 2000 05:55:47 UTC