Re: [xsl] Generating XSD Schema files from XML source files

Subject: Re: [xsl] Generating XSD Schema files from XML source files
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Tue, 09 Nov 2010 14:51:20 +0000
Generating a schema for an XML file is a non-trivial task, unless of course you want to generate a trivial schema - one which every conceivable document conforms to. Of course there are an infinite number of schemas that any document conforms to: some of them might allow only that one document, and no others. So a lot depends on why you are doing it, and on how constraining you want the schema to be. It's not clear from your description whether you want a different schema for each source document (in which case you're not going to be able to hand-tune them at all), or whether you want a schema that all 500 source documents conform to.

All the IDEs such as Stylus Studio and oXygen have tools that will generate a schema from a source document, and they do a pretty respectable job, though the results need hand-tuning to be usable in practice. But they do tend to work on individual document instances rather than batches.

Doing it yourself in XSLT sounds like hard work. So although your question is on-topic for this forum, the answer isn't...

Michael Kay
Saxonica


On 09/11/2010 14:26, Neil Owens wrote:

I have a need to generate XSD Schema files from source XML files and I've no idea what would be the current 'best practice' way to go about it?


Just write an XSL transform that does the XML result file to Output and the schema to a result-document? Or something else/better?

I've approx 500 XML source files where parts of each one need placing into a database. What I've done so far, with Saxon9 and XSLT2, combined with this - http://msdn.microsoft.com/en-us/library/ms171806.aspx - does it all, except generating the Schema file.

TIA!

Current Thread