Re: scoping of namespace prefix

Jeni Tennison <jeni@jenitennison.com> writes:

> 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.

I'm not sure I understand what you mean by prefix collision -- how
does XSV fail with that above schema? 

> 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.

It's I suppose possible that fooB.xsd and
fooC.xsd are compatible with one another -- i.e. either identical, or
not contradictory.  In that case in principle you could put _both_
pairings in a single xsi:schemaLoc, e.g.

      <foo:B xsi:schemaLocation="http://foo.namespace fooB.xsd
                                 http://foo.namespace fooC.xsd">
              <foo:Q />
              <foo:R />
      </foo:B>
      <foo:C>
              <foo:Y />
              <foo:Z />
      </foo:C>

I don't _think_ that there's anything in the REC which precludes the above.

ht
-- 
  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
          W3C Fellow 1999--2001, part-time member of W3C Team
     2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
	    Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
		     URL: http://www.ltg.ed.ac.uk/~ht/

Received on Monday, 3 December 2001 15:33:36 UTC