[xsd-users] Attributes not found from imported schemas

Boris Kolpackov boris at codesynthesis.com
Mon Nov 26 15:50:36 EST 2007


Hi Mark,

mhoffm1060 at aol.com <mhoffm1060 at aol.com> writes:

> What they are trying to do here is the schema in main.xsd is a released
> version, and the schema in ext1.xsd is an extension to the schema defined
> in main.xsd. Is this a good way to do this or is there a more preferable
> way? We have some input to the outside source of these schemas, so if
> there is a better way to extend the main schema they might be open to it.

The problem is not really in the structure of your schemas but rather
in how you import them. When you import a schema, you specify the
schema namespace which XML Schema processors use as a key in a map
of grammars. One use for this map is to determine if a grammar for
a particular namespace has already been parsed. In other words,
when a schema processor sees an xs:import declaration, it checks
if there is already an entry in the grammar map and if so, the
import declaration is ignored.

One consequence of this approach is that if you have a first import
declaration (as seen by the processor) that specifies one schema
file and then a second import declaration which specifies a different
file with additional types and/or elements, then this second schema
file and all extra declaration in it will be ignored. This is why it
is advised to always import declaration for a particular XML vocabulary
using the same, top-level schema file.

In your case here is what happens when main.xsd is compiled: when
main.xsd is opened, the 'main' namespace is entered into the map.
Then ext1.xsd (imported from main.xsd) is processed. This file
contains an import declaration for the same 'main' namespaces
by with a different schema file: myIncludes.xsd. Since this
namespace is already known, myIncludes.xsd and all declarations
in it are ignored. This results in the error you observe.

The proper way to fix this is to import the 'main' namespace with
the same schema file (main.xsd) everywhere. That means changing
ext1.xsd to import main.xsd instead of myIncludes.xsd. While this
will work, the resulting schemas will have a cyclic dependency:
main.xsd needs Data from ext1.xsd and ext1.xsd needs myValue from
myIncludes.xsd via main.xsd. The generated C++ code for such a cycle
will work as long as there is no type inheritance involved. One
way to address this cyclic dependency would be to put all three
schemas in the same namespace and use the original inclusion
graph: main.xsd->ext1.xsd ext1.xsd->myInclude.xsd.

Another approach that will work in this particular case would be
to reorder the import and include declaration in main.xsd so that
types in myIncludes.xsd are declared before ext1.xsd is processed.

Boris




More information about the xsd-users mailing list