Generating samples out of a schema

For one of my projects, I need to generate sample documents out of a W3C XML Schema.

I had a quick look on existing products but ruled tham out since I don’t believe they meet the requirements imposed by my customer:

  • The values need to be « significant » (no « abcd » for a name).
  • The schema is using some advanced WXS features such as derivation and xsi:type.

I plan to implement that as a two step XSLT transformation:

  1. The WXS schema is transformed into a simplified RELAX NG schema.
  2. The simple RNG schema is used to generate the samples.

The benefit of having a valid schema as the intermediate document between the two steps is that that should facilitate the debugging: if a sample document isn’t valid per the original schema, a validation against the intermediate schema should show if the bug is in step one or step two.

The reason why I have chosen RELAX NG for this intermediate schema is that it’s easier to write and easier to process but also that I can have a single schema for all the namespaces used in the original schema (that wouldn’t be possible with a W3C XML Schema).

I plan to code lists of meaningful values as WXS schema annotations and convert these annotations into RELAX NG choices so that all the alternatives (both in the achema itself and in the meaningful values) are translated into RNG choices in the intermediate schema.

Not trivial, quite a lot of work but that seems feasible to me!

2 thoughts on “Generating samples out of a schema”

  1. Hmmm… I had forgotten, since my last similar work with W3C XML Schema (ie when I have written a transformation to generate the structure of the reference manual of my XML Schema book) how tedious this kind of work is and I am progressing far slower than expected :-( …

    I wish the original schema could have been written with RELAX NG!

Répondre à Eric van der Vlist Annuler la réponse

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *