1. Problem
You need to create a mapping
between two schemas containing elements and attributes that are unknown
when building the map, and you must include the unknown schema
structures in your mapping.
2. Solution
You can include unknown
schema structures in a map by using the <Any> element.
Build
a source message schema containing an <Any> element. This can be done by right-clicking the record in
the schema and selecting Insert Schema Node => Any Element, as shown in Figure 1.
Build a destination schema containing an <Any>
element, as shown in Figure 2.
Add a new map to the solution.
Set the source and target schemas appropriately.
Click the Toolbox, and then click the Advanced Functoids
tab. Drag a Mass Copy functoid onto the map surface. Connect the Address element from the source message to the Mass
Copy functoid, and connect the Mass Copy functoid to the Address
field of the destination message.
Create other
desired mapping links normally, as shown in Figure
3.
3. How It Works
An <Any>
element in a schema designates a specific location in the schema where
new elements or attributes can be added. When BizTalk uses the schema to
process a message containing unknown elements or attributes in the
designated location, the schema will still consider the message valid.
If this source message is mapped into a different schema that also has a
location designated for extensibility with an <Any> element, then the information must be copied to
that location with the Mass Copy functoid.
NOTE
By default, BizTalk
will examine only the namespace and root node name of a message to
identify the schema, and will not detect extra elements in the message
body. To perform a deep validation of a message format, create a receive
pipeline with the XML disassembler, specify the schema to validate
messages against, and set Validate Document Structure to true.
The contents of an <Any> element cannot be mapped with most of the default BizTalk
functoids. Other functoids require establishing an explicit link from a
source field, and that is not possible if the source field is not known
at design time. The Mass Copy functoid can be linked only directly to an
ancestor of the <Any>
element, which may not give the granularity of control desired. Consider
using an XSLT script with the Scripting functoid to achieve finer
control. For example, if you know some element will be present at
runtime but cannot predict the element name of its parent, an XSLT
script can still perform the mapping.
Note that you can override the
mapping of the mass copy on a line by line basis. For instance, if the
Zip field needs to be mapped differently, simply add the appropriate
functoid(s) and map it; this will override whatever the Mass Copy
functoid has created (see Figure 4).
Sometimes, the
BizTalk development environment has difficulty validating schemas
containing <Any> elements.
It can incorrectly determine that elements and attributes appearing in
the location designated by the schema should not be there, causing
validation for the schema to fail. This complicates schema development
because the developer must deploy the schema with a pipeline capable of
validating the document structure to check if the schema is correct
according to a sample source message. To avoid this deployment effort
while developing the schema, wait to add <Any> elements until the rest of the schema is developed and verify
that those other elements are defined correctly. Then, when adding the <Any> elements to the schema, there will be a
baseline of what is working correctly.
The Mass Copy functoid allows
source records and containing elements and attributes to be copied and
mapped across to the destination schema. This in turn, allows large
structures to be mapped quickly in design time, without the need of
performing 1:1 detailed mapping on all subsequent schema nodes. The Mass
Copy functoid performs the recursive copying by applying a wildcard (/*) XSLT template match on source to destination XML
elements. This is of particular benefit when the destination is defined
as an <xs:any> type.
When mapping from source to
destination, only the structure under the destination parent XML record
will be copied. This often results in having to re-create the parent
record element to allow all subsequent children nodes to be mapped to
the destination schema. For example, consider the following two schemas,
CustomerCustomers: and
<Customer>
<Name> </Name>
<AccountID> </AccountId>
<DOB> </DOB>
</Customer>
<Customers>
<Customer>
<Name> </Name>
<AccountID> </AccountId>
<DOB> </DOB>
</Customer>
</Customers>
In this instance, the <Customers> record cannot be mapped to the <Customer> record on the destination schema. A containing
element <Customer> will need to
be defined on the destination schema to enable the correct operation of
the Mass Copy functoid mapping.
When mapping source to
destination elements, always be cautious of underlying XSD schema rules,
such as cardinality, order, and data types. For example, the Mass Copy
functoid will "blindly" copy all child elements specified to the
destination schema. It will not copy elements out of order or check for
required values in the destination schema.
Changes to the source and
destination schema may result in the need to update your impacted maps
leveraging the Mass Copy functoid. This, in turn, will mandate a
recompile and deployment of your BizTalk solution.
Using the Mass Copy
functoid within the BizTalk Mapper is one of a variety of ways to
recursively copy elements. The following are three key approaches to
recursively copy XML structures:
Mass Copy functoid: Creates a wildcard XSLT template match to
recursively copy elements. This approach may provide a performance
benefit, as each source and destination element does not require a 1:1:
XSLT template match. This, in turn, requires fewer XSLT code
instructions to be interpreted and executed at runtime.
Recursive
mapping: This is achieved by holding
down the Shift key and mapping from a source to destination record
element. This is a usability design feature that enables a developer to
perform recursive mapping via one keystroke. This approach implements
1:1 XSLT template matches on all source and destination elements.
Straight-through mapping: This approach is to manually link all source
and associated destination elements within the BizTalk Mapper tool. This
method does 1:1 template matches on all source and destination
elements.