[xsd-users] Attributes not found from imported schemas

mhoffm1060 at aol.com mhoffm1060 at aol.com
Mon Nov 26 18:05:16 EST 2007


Boris,
Thank you for your quick and informative response.? 

Another question if I may: ?is this usual in the XML world ( to ignore additional imports of the same namespace )?? I was reading the spec ( http://www.w3.org/TR/xmlschema-1/#composition-schemaImport?see Note an the end of section: 4.2.3 References to schema components across namespaces?), and while the spec allows this, it mentions that this is risky behavior.

I'm asking because the entity that we receive these schema from declare that they are compliant to the above spec.? ( Apparently they are ), but if it is an industry practice to ignore the later imports, I'll have some leverage to get them to change the structure.

( I understand that by reorganizing the schemas I can get it to work.? However this is not a static schema and will be expanded this way on a periodic basis.? Therefore I would have to apply the modifications every time a new schema comes out, instead of getting it ready to use. )

Thanks,
Mark


-----Original Message-----
From: Boris Kolpackov <boris at codesynthesis.com>
To: mhoffm1060 at aol.com
Cc: xsd-users at codesynthesis.com
Sent: Mon, 26 Nov 2007 12:50 pm
Subject: Re: [xsd-users] Attributes not found from imported schemas



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


________________________________________________________________________
Email and AIM finally together. You've gotta check out free AOL Mail! - http://mail.aol.com



More information about the xsd-users mailing list