I've decided to update and repost this from 2004 since I've gotten quite a few emails asking about schema generation, document normalization and "industry standard" schemas like cXML, xCBL and PIDX.
In wood-working there is a time honored saying “Measure Twice, Cut Once”. In BizTalk Server 2004, I think the saying should be “Map Twice, Code Once”. I've been working with custom cXML schemas (generated from well-formed sample documents downloaded from the cXML web site) for a vendor integration scenario and have run into the problem of having to map from one complex format to another, even more complex format. The answer turns out to be quite simple but not obvious (hindsight is definitely 20-20). A major supplier to my company has implemented the cXML “OrderRequest” DTD using BizTalk Server 2002 and wanted to receive purchase orders in this format. The cXML DTD was pretty easy to “migrate” to a BizTalk schema using the “Add Generated Items” menu and selecting a well-formed XML sample to use. For those of you not familiar with cXML (which I wasn't until this project), the XML format used is “mixed” (it uses both attributes and elements to hold data) and the generated schema is pretty complex as shown below.

Figure 1: Partial cXML Schema
Mapping from our ERP system's flat-file output to this complex cXML format looked pretty daunting until I decided to use “normalization” to break down the mapping into two steps. First I created a simple internal purchase order XML schema (shown below) that would be used to bridge the gap between a complex flat-file schema and a complex cXML schema.

Figure 2: Simple Internal Schema
Next I created a map from our ERP system's flat-file format to this new internal XML format and placed the map in a custom receive pipeline. This transforms the inbound flat-file into our much simpler internal XML format and publishes it to the MessageBox for further processing. After this, I also created a map from the new internal XML format to the outbound cXML format and placed this map in a custom send pipeline. Now I can write whatever orchestration and/or business rules I need based upon a simple, well-known, internal XML format rather than a complex flat-file or cXML format. The send port then subscribes to this message, transforms it into the required cXML format and sends it to our trading partner. This simple “normalization” technique using maps in the receive and send ports has saved me countless programming hours and is one of the “hidden gems” of BizTalk Server 2004.