BizTalk schemas are most commonly used to alter data in a message and route it to a new destination. BizTalk Server can take data from an incoming message and copy it to a new message, or use the data to make a decision about further action. All of this data processing requires the use of XML schemas in order to read and write the data accurately.
When BizTalk Server receives messages from one computer system, it uses schemas to convert the message into the format required for a different computer system. A source schema tests the data in the incoming message and uses a destination schema to transform it to the appropriate data in the outgoing message. For example, you may have messages coming in from a furniture store requesting a chair from the warehouse. The format of the incoming message from the store may look like this:
<Chair>
<ID>040754</ID>
<Price>59.52</Price>
<Color>Red</Color>
</Chair>
However, if the computer at the warehouse uses a different message format, it may be expecting a message that looks like this:
<Chair>
<ID>040754</ID>
<Hue>Red</Hue>
</Chair>
If you send the message from the store directly to the warehouse, the warehouse computer won't be able to read the message correctly, because the data fields won't match. The data fields won't match because the data in the incoming message has three sections (ID, Price, Color), but the outgoing message has only two (ID, Hue).
You can use BizTalk Server to solve this type of problem by defining a transformation relationship between a field in one message and a field in another. You define this relationship by using BizTalk Mapper, a visual tool that you use to drag and drop the relationship criteria into place.
After you have created the relationship by using the editor and the mapper, BizTalk Server provides many different ways to copy, transform, and route the data by using pipelines and orchestrations.
Using the Mapper
BizTalk Mapper uses a visual drag-and-drop user interface to define transformational relationships between fields in one message and fields in another message. After you have promoted the properties you wish to use, you need to create a map file that outlines the relationships.
To create a map file using the BizTalk Mapper
-
In Solution Explorer, right-click the solution name, point to Add, and then click Add New Item.
-
In the Add New Item dialog box, click the Map Files folder.
-
In the Name box, type a unique name for the map file, and then click Open.
The following figure shows the Add New Item dialog box.
Figure 1 Add New Item dialog box
You can display the contents of the new map file by double-clicking the map file name in Solution Explorer. The following figure shows a blank map.
Figure 2 Blank map file
Click Open Source Schema and Open Destination Schema to add schemas to the map. After you have inserted the schemas, you can drag the mouse pointer from the properties in one schema to the properties in another. When you release the mouse, a line appears showing the link between the two properties. The following figure shows a sample map with the relationships drawn in.
Figure 3 Sample map file
Using XML schemas and relationship mapping enables BizTalk pipelines and orchestrations to receive, transform, and send messages from one computer system to another.
Note |
|---|
|
When you build a BizTalk solution and do not add a map, BizTalk Server may create a default map for you and define default relationships between incoming and outgoing message fields. If you are not aware of this, you may get unexpected results. For this reason, it is recommended that for most solutions, you use BizTalk Mapper to create a map and define the relationships.
|
Promoting Properties in Schemas
A schema can have many elements, but your application may only require that you use a few of them for your data processing. To save computer resources, BizTalk Server doesn't automatically read each schema element. If you want BizTalk Server to read data from a specific element, you must identify that element by using BizTalk Editor to promote its properties.
Use the following steps to promote a property that you wish to identify.
To promote a property
-
Open the desired schema in BizTalk Editor.
-
Select the schema field node you want to promote.
-
Right-click the field node and then click Promote.
-
Click Show Promotions.
-
In the Promote Properties dialog box, click Add to add the field to the promoted properties list.
The following figure shows the Promote Properties dialog box with a field named PetType.
Figure 4 Promote Properties dialog box
When you promote a property, you add code to the schema. In the preceding example, when you promote the PetType field, the following code will be added to the root node of the schema:
<b:properties>
<b:property distinguished="true" xpath="/*[local-name()='Pets' and namespace-uri()='http://ffdelrec.ffdelrec']
/*[local-name()='StudentPets' and namespace-uri()='']/*[local-name()='PetType' and namespace-uri()='']" />
</b:properties>
After a property is promoted, BizTalk Server has the information it needs to process the property with the mapper and to create a transformation relationship.
For more information about BizTalk Mapper and about promoting properties, see BizTalk Server 2004 Help.
When you create a schema, the structure of the schema may not be correct. BizTalk Server provides a way to test the accuracy of the schema to make sure that it is internally consistent and valid.
To validate a schema for accuracy, add the schema to the BizTalk project and right-click it in Solution Explorer. One of the options will be to validate the schema. Select this option and BizTalk Server will run tests on the schema to make sure that it is constructed properly. If there are any errors, they will be displayed in the output window.
To validate data in an XML message, you can use schemas embedded in a custom pipeline. See BizTalk Server 2004 Help for more information about advanced types of data validation.