This post disappeared from a previous blog of mine so I'm reposting it.

I've been doing some research on custom adapter development and one of the issues that came up was figuring out how to do the schema generation.  BizTalk Server 2004 includes a wizard that will generate schemas from Xml instance documents.  I decided to figure out how it worked – and if it could be reused.

 

It is possible to reuse this functionality.  Here's how you do it:

 

  1. Create a console project.
  1. Reference the Microsoft.BizTalk.WFXToXSDGenerator.dll and XSDInfer.dll assemblies in the [installDir]\Microsoft BizTalk Server 2004\SDK\Utilities\Schema Generator directory. 
  1. Reference the Microsoft.BizTalk.SchemaEditor.Extensibility.dll assembly in the [installDir]\Program Files\Microsoft BizTalk Server 2004\Developer Tools directory.
  1. Pull in the Microsoft.BizTalk.WfxToXSDGenerator namespace.
  1. Add the following code to your Main method:

 

WfxToXSDGenerator gen = new WfxToXSDGenerator();

 

gen.GenerateSchema(args[0], args[1]);

 

object[] warnings = gen.Warnings();

object[] errors = gen.Errors();

object[] schemas = gen.ReferencedSchemas();

 

if(warnings.Length != 0)

{

Console.WriteLine("Warnings were found:");

 

          for(int i = 0; i < warnings.Length; i++)

          {

        Console.WriteLine(warnings[i].ToString());

          }

 

          Console.ReadLine();

          return;