Data Management Blog: SchemaLightener gets a Flattener


Data Management Blog
Data management, Cloud, Transformation and anything else...

SchemaLightener gets a Flattener

I've added a new feature to the Xml SchemaLightener, namely that of a Flattener. First, here are some definitions:

Lighten: to remove elements and types from a schema, while the remaining elements and types are still consistent with the original schema. To "prune", or create a subset of the schema. To create a "view" of the schema, focusing on certain components.

Flatten: to merge all schema dependencies connected via xsd:include into a single schema file. To create a "stand alone" version of a set of schemas. All components are consolidated into one file without any editing or changes. Does not pertain to dependencies connected via xsd:import (because this will not result in a valid schema).

I've often needed a flattening tool. Schemas are usually developed modularly to maximize reuse. This has tremendous benefits in building a data model. However, come deployment time, tools sometimes have a problem managing a web of xsd:include files. So it is generally recommended to create a runtime version of a schema which consolidates includes into a "stand alone" one. (Of course it may not literally be stand alone because of xsd:import files, but it isn't possible to merge these according to the spec.)

The difference between xsd:include and xsd:import is in namespaces. Files connected via xsd:include have the same default namespace. This is what allows them to be consolidated into a single schema. Files connected via xsd:import have different default namespaces.

So I've thrown in an XSLT which will create a stand alone or flattened schema into the SchemaLightener tool. Importantly, even though imports cannot be merged, it does automatically go to each import and flatten its includes (if any) and so the result is a fully valid set of schemas that may have imports but no includes.

In short, the absolute minimum number of schema files possible.
© Copyright Paul Kiel.