1. Problem
You would like to map one XML
format to another using the BizTalk tool set. This may be for a variety
of reasons, such as application mapping with an internal application,
format specifics (such as flat file to database object), or an external
business scenario where a business partner requires the core data for a
business process in a different format (such as an industry standard)
than your schema provides.
2. Solution
The BizTalk Mapper enables
you to perform XML message transformation. The tool is shipped with the
core BizTalk product and provides numerous capabilities to support
message transformation and translation via straight mapping and
functoids, as well as unit test support.
NOTE
The term functoids refers to predefined functions within the
BizTalk Mapper tool set. Functoids support a number of useful
translations and transformations. As a point of interest, functoid is a term
coined by Microsoft and is commonly described as "functions on
steroids."
As an example, suppose that
you have the following simple customer schema (Customer):
<Customer>
<FirstName> </FirstName>
<LastName> </LastName>
<MiddleInit> </MiddleInit>
<Age></Age>
<Address>
<AddrLine1> </AddrLine1>
<AddrLine2> </AddrLine2>
<AddrLine3> </AddrLine3>
<Zip> </Zip>
<State> </State>
<Country></Country>
</Address>
</Customer>
And you want to map to another
customer schema (CustomerRecord) that
is slightly different in structure and format:
<CustomerRecord >
<Name> </Name>
<MiddleInit> </MiddleInit>
<Address> </Address>
<Zip> </Zip>
<State> </State>
<Country> </Country>
<DateTime> </DateTime>
</CustomerRecord>
The example involves
mapping values from a source to a destination schema that subsequently
demonstrates different structure and invariably, message transformation.
To create the BizTalk map for the example, follow these steps:
Open
the project that contains the schemas.
Right-click the project,
and select Add => New Item.
In the
Add New Item dialog box, shown in Figure 1, click Map and give the file name a valid name. Once
completed, click the Add button.
A blank map will now be opened,
with left and right panes for the source and destination schema,
respectively, as shown in Figure 2. Click the Open Source Schema link in the left
pane.
In the BizTalk Type Picker
dialog box, select the Schemas tree node, and
then select the Customer schema (see Figure 3).
Click OK.
Click the Open Destination
Schema link in the right pane.
In
the BizTalk Type Picker dialog box, select the Schemas tree
node, select the CustomerRecord
schema, and click OK. The source and destination schemas will now be
displayed.
Perform the straight-through mapping. Click the MiddleInit element in the source schema, and drag it across
to the MiddleInit element in the destination
schema. Repeat this for the Zip, State, and Country
elements.
Perform the concatenation mapping.
NOTE
The term concatenation
mapping within the BizTalk Mapper
refers to the joining of two or more values to form one output value.
Here are the steps to follow
in order to perform the concatenation.
In
the left pane, click the Toolbox, and click the String Functoids tab.
Click and
drag two String Concatenate functoids onto the map surface, as shown in Figure 4.
Click the FirstName
element in the source schema and drag it across to the left point on the
first String Concatenate functoid. Click the right side of the String
Concatenate functoid, and drag it across to the Name element in
the destination schema.
Double-click the
first String Concatenate functoid. Click the Plus button (this will add a
new input), and create a constant that has a space in it (see Figure 5).
Click the LastName
element in the source schema, and drag it across to the left point on
the first String Concatenate functoid. This will complete the mapping of
Name.
Click the AddrLine1
element in the source schema, and drag it across to the left point on
the second String Concatenate functoid. Click the right side of the
String Concatenate functoid, and drag it across to the Address element in the destination schema.
Repeat step 6 for AddrLine2
and AddrLine3, adding a comma
between each address field. Figure 6 shows the completed concatenation
mapping.
To demonstrate functoid usage,
you will now add a Date and Time functoid to the mapping example. In
this instance, the destination schema requires a date/time stamp to be
mapped. This value will be generated from the Date and Time functoid,
not the source schema.
In
the left pane, click the Toolbox, and then click the Date/Time
Functoids tab (See Figure 7).
Click and drag a Date and Time
functoid onto the map surface.
Click
the right side of the Date and Time functoid, and drag it across to the
DateTime element in the
destination schema.
The map is now complete, as
shown in Figure 8.
3. How It Works
The BizTalk Mapper is used
to map XML messages (instances of XML schema at runtime) to an
alternate format based on transformation and/or translation. It is built
on XSLT and shields the user from complex XSLT transformation logic, by
providing a GUI environment to facilitate the transformation. The tool
comes with numerous functoids and mapping capabilities to support
straight-through and deterministic transformation. In addition, the tool
gives the built-in ability to perform unit testing.
The maps created within the
BizTalk Mapper environment can be used within other BizTalk runtime
environments. For example, they can be used with receive/send ports, for
transforming a message to and from application end points. Port mapping
might be advantageous when the mapping involves minimal process
considerations or the need to apply multiple maps to a given message.
Changes to maps on ports can be completed without recompilation of
currently deployed BizTalk assemblies. Maps can also be used with
transformation shapes, for message transformation within a BizTalk
orchestration. Mapping within an orchestration might be preferred when
the mapping process involves broad process considerations or process
support via robust exception and error handling.
The choices for where and
when to map vary depending on a number of factors. A number of these
have to do with common development principals (such as consistency and
readability) and standards enforced by the environment in which you are
operating. However, a few common rules of thumb should be noted:
Keep it simple: Keep maps logically organized. Across maps,
ensure that the same look and feel are applied for consistency.
NOTE
Just because you can
create a map using the mapper and functoids doesn't always mean you
should. Make sure that whatever maps you create are simple and
maintainable. Highly complex maps with many interlocking functoids can
become unwieldy and next to impossible to support. Alternatives to
mapping (most notably XSLT) are often very intelligent alternatives.
Keep business rules in mind: Based on the deterministic ability of mapping,
be careful or keep in mind the usage of business rules within maps. If
you find you are using rules within maps (for example, If OrderTotal
> $1000), keep in mind maintenance
and where in your organization a decision may be made to change this
rule. In addition, always consider the right place to maintain rules and
context domain knowledge from an operation and support perspective.
Consider performance: While mapping is powerful, complex and/or large
maps can affect performance. As with all common development activities,
always ensure that the logic performed is the most efficient and tested
for scale in your practical operating conditions and requirements. If
you experience performance issues, employ techniques such as revisiting
design by exploring the solution breakdown. Consider simplifying the
development task at hand.
Like all good
development processes, maps should be designed and tested for desired
application operation conditions.