W3C home > Mailing lists > Public > xmlschema-dev@w3.org > December 2001

Re: How to refer to another Schema from a Schema?

From: Jeni Tennison <jeni@jenitennison.com>
Date: Wed, 19 Dec 2001 19:04:23 +0000
Message-ID: <6327343287.20011219190423@jenitennison.com>
To: Shweta Sinha <shwet_sam@yahoo.com>
CC: xmlschema-dev@w3.org
Hi Shweta,

> I would like to know how to create a generic schema doc which will
> be referred to by all my other schema documents in the namespace?
>
> Say I have atag called Error:
> <ERROR>
> <TYPE></TYPE>
> <DESC></DESC>
> </ERROR>
>
> this node / tag has to be included in all my schemas. Instead of
> adding to each schema I want have a separate doc containing just
> this tag & referred to by all the other schema docs.

No problem. Declare the ERROR element as a global element in one
schema, then include that schema into your other schemas with
xs:include:

<xs:include schemaLocation="error.xsd" />

You can then refer to the declaration of the ERROR element in just the
same way as you would if it were declared in the including schema.

If the various schemas that you need to use the ERROR element within
are all in different namespaces, then you should have no target
namespace in the shared schema. The shared schema will then 'adopt'
the target namespace of the schema in which you include it. If they're
all in the same namespace, I think it's better practice to make sure
that the target namespace of the shared schema is the same as the
ones in which it's used.

See http://www.w3.org/TR/xmlschema-0/#SchemaInMultDocs for an example.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Wednesday, 19 December 2001 14:04:25 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:25 GMT