BizTalk Server Tips and Tricks: Automatically Generate Schemas from a Well-Formed XML instance

Welcome back to my blog post series “BizTalk Server Tips and Tricks” for developers, administrators or business users.

There are several ways we can create an XML Schema in BizTalk Server:

  • Manually from scratch
  • From XDR Schema instance
  • From a DTD instance
  • From a well-formed XML instance
  • Import them from a WCF Service or Web Service
  • Automatically generated them from LOB systems (from the adapters)

Today, we will be talking about automatically generating XML Schemas from a well-formed XML instance. To accomplish this we need to perform the following steps:

  • In Solution Explorer, right-click a BizTalk project, point to Add, and then click Add Generated Items…

BizTalk Server: Generate Schemas from a Well-Formed XML

  • In the Add Generated Items – <BizTalk ProjectName> dialog box, in the Templates section, click Generate Schemas, and then click Add

BizTalk Server: Generate Schemas from a Well-Formed XML

  • In the Generate Schemas dialog box, in the Document type drop-down list, select Well-Formed XML

BizTalk Server: Generate Schemas from a Well-Formed XML

  • One of the problems, especially in brand new installations, is that sometimes this feature was not installed, and you will see Well-Formed XML (Not Loaded) in the drop-down list. To install and use this feature you need to:
    • Start a Windows Explorer and navigate to the “SDK\Utilities\Schema Generator” folder present in the BizTalk Server installation folder;
      • Normally it will be “C:\Program Files (x86)\Microsoft BizTalk Server <version>\SDK\Utilities\Schema Generator”
    • Execute the InstallWFX.vbs script by double-clicking. This will install the “Microsoft.BizTalk.WFXToXSDGenerator.dll” DLL on the correct place
      • That basically means, it will copy this DLL to the “Developer Tools\Schema Editor Extensions” folder present in the BizTalk Server installation folder
    • Or manually copy “Microsoft.BizTalk.WFXToXSDGenerator.dll” DLL to the “Developer Tools\Schema Editor Extensions” folder, present in the BizTalk Server installation folder
      • Normally, it will be “C:\Program Files (x86)\Microsoft BizTalk Server <version>\Developer Tools\Schema Editor Extensions
  • Close the Generate Schemas dialog box and do the previous steps again, and now you will be able to see that you already can use the option Well-Formed XML in the drop-down list.

BizTalk Server: Generate Schemas from a Well-Formed XML

  • In the Generate Schemas dialog box, click Browse, locate the file you want to import, click Open and then click OK

BizTalk Server: Generate Schemas from a Well-Formed XML

  • A new schema, or sometimes at least two schemas are generated from the specified file, using the same name as that file with the .xsd extension, and opened in BizTalk Editor

TIP: Before you generate the schemas, rename the XML instance file that you will be using to the proper name you want to give to the Schemas, this will save you time because the Generator Wizard will:

  • Give the same name of the specified file with the .xsd extension
  • Or will add a sequence to the same name of the specified file with the .xsd extension

BizTalk Server: Generate Schemas from a Well-Formed XML

In the end, as a best practice, you should rectify or rename the schemas generated to something with context and that will be easy to identify:

BizTalk Server: Generate Schemas from a Well-Formed XML

If you want it to be perfect, then for each schema, you should change not only the name of the file, but also the Type Name property of each schema.

BizTalk Server: Generate Schemas from a Well-Formed XML

Initially, this value was set as “myfilename_0”.

The problem of renaming the filename and/or the Type Name property is that once you try to compile it will give you errors because some schemas will be referring files that no longer exist (were renamed):

BizTalk Server: Generate Schemas from a Well-Formed XML

To solve this, we need to:

  • Open the Schema and select the Schema node at the top of the schema tree view
  • In the Properties window, in the Advanced category, in the value portion of the Imports property, click the ellipsis () button
  • In the Imports dialog box, in the Import Schema list, delete the XSD Import line, import the correct one and then click OK

BizTalk Server: Generate Schemas from a Well-Formed XML

  • Alternatively, open the schema file in Notepad (Notepad ++ or other text editors) and rectify the path and filename

Quick, simple and practical!

Stay tuned for new tips and tricks!

Author: Sandro Pereira

Sandro Pereira is an Azure MVP and works as an Integration consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc.

Back to Top