[xsd-users] dynamic xs:include's in schemas

Boris Kolpackov boris at codesynthesis.com
Thu Jun 4 10:09:34 EDT 2009


Hi Benjamin,

Benjamin Schindler <bschindler at inf.ethz.ch> writes:

> We're building a client-server system which uses xml to pass the data  
> around. We use xsd to access and parse the data which is being passed  
> around.
> Now the idea of a plugin-system came up. Right now, the main schema used  
> for validation just has an include for every part component of the  
> system like this:
> ....
>    <xs:include  
> schemaLocation="../../../views/views/schema/ScatterSettings.xsd" />
> ....
> Now when I dynamically load a plugin, I cannot hardcode these includes  
> into the xsd anymore.
> Is there a way to tell the parser about more includes in any way without  
> actually modifying the xsd directly on disk?

There is no such include facility but there is a way to get rid of the
xs:include altogether by using XML Schema wildcards (xs:any and 
xs:anyAttribute). The idea is to define an "extension point" in the
schema as a wildcard. You can then define independent schemas that
define the concrete extensions used in its place. The 'wildcard'
example in the examples/cxx/tree/ directory shows how this might
work. If you need validation you may also need to manually load all
the "concrete" schemas (see the 'caching' example on how to do this). 

Another, more OO, alternative is to used substitution groups. In this
case your define an abstract type and element that are then derived
from in separate schemas (in this case the "concrete" schemas will
include the "base" but not vice-verse). See the 'polymorphism' example
for information on how this might work. The advantage of this method
is that everything is handled for you under the hood (i.e., you  don't
need to work with DOM to parse the data matched by wildcards).

Boris




More information about the xsd-users mailing list