Re: scoping of namespace prefix

Hi Naomi,

> I'm running into a problem with prefix scoping.
>
> My instance document (simplified):
>
> <bar:A xmlns:bar="ignored" xmlns:foo="http://foo.namespace"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>  xsi:schemaLocation="ignored bar.xsd">
>         <foo:B xsi:schemaLocation="http://foo.namespace fooB.xsd">
>                 <foo:Q />
>                 <foo:R />
>         </foo:B>
>         <foo:C xsi:schemaLocation="http://foo.namespace fooC.xsd">
>                 <foo:Y />
>                 <foo:Z />
>         </foo:C>
> </bar:A>
>
> I have XML schemas bar.xsd, fooB.xsd and fooC.xsd, all of which are
> valid. I can't find anything in the XML Schema spec that implies the
> above instance doc shouldn't work. But there seems to be a namespace
> prefix collision for prefix "foo." This is true for XSV and for the
> topologi Schematron Validator.

The problem is that you can't change the association between a
namespace and a schema half way through a document. On any single
assessment, a schema validator will only consider one schema for a
particular namespace.

The xsi:schemaLocation (or xsi:noNamespaceSchemaLocation) attribute
that defines the association between a namespace and a schema has to
be on or before the first element in the document with that namespace,
but then has a scope beyond (after) that element as well. This is
described in http://www.w3.org/TR/xmlschema-1/#schema-loc.

Effectively this means that you may as well define all your
associations between namespaces and schemas on the document element.
If you have different schemas for different sections of the document,
I'd recommend that you use different namespaces for those different
sections.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Monday, 3 December 2001 05:44:27 UTC