Powered By

Free XML Skins for Blogger

Powered by Blogger

Friday, January 9, 2009

Structure Mapping by Setting the Context in XI Message Mappings

In the default setting, each field is in the context of the higher-level field.

This graphic is explained in the accompanying text

Fix and Foxy are in the first flat context, Jolly Jumper and Lucky Luke are in the second, and all four are in the first street context. The first field is in the first city context and so on.

Let us assume that you want to map this structure to the following list to include all those people from the first city and the first street:


The root node (in this case ) always appears exactly once. This is displayed explicitly in the target structure.

You want to list all four people from the first street context (Fix, Foxy, Lucky Luke, and Jolly Jumper). Define a target field mapping for :

\personList\person=\root\city\street\flat\person

This XML instance produces the following result:


Fix
Foxy

It only generates Fix and Foxy from the first flat context. To understand why this is the case, we can look at the processing:

...

1. The root node is generated because it is obligatory.

2. The message mapping checks in the context whether there is a target field mapping for \personList\personand whether there are values for this in the XML instance. The mapped \root\city\street\flat\person field is in the first flat context.

3. The message mapping generates fields in the target structure for Fix and Foxy in the first flat context. Once the first flat context has been processed it is closed along with the context in the target structure.

The transformation is completed with the last step because all target structure fields have been processed. The example shows the following:

· The structure node is implicitly assigned to the root node during mapping. is generated as often as is predefined in the schema, therefore once (see also: Mapping Fields Within a Context).

· The list only includes Fix and Foxy because they are in a different context to Jolly Jumper and Lucky Luke.

You can set the context individually for each field in the source structure in the Data-Flow Editor context menu. If you set the context for \root\city\street\flat\person, then prior to the mapping, all fields are appended to the next highest field, which is . Depending on how you set the context in the source structure, you will get the following results:

Structure Mappings Using Different Contexts of the Source Field

Context of \root\city\street\flat\person

Results list

flat (default setting)


Fix
Foxy

street


Fix
Foxy
Jolly Jumper
Lucky Luke

city


Fix
Foxy
Jolly Jumper
Lucky Luke
Asterix
Obelix

root


Fix
Foxy
Jolly Jumper
Lucky Luke
Asterix
Obelix
Valerian

The removeContexts() standard function assigns the fields assigned to it to the root node. You will get the same effect if you assign the root context to this type of field.

The higher-level context of an attribute is the element to which it is assigned. The above statements relating to fields also apply to attributes.

Technically speaking, the XML instance is imported into the queues before the target field mappings are processed. The contexts are separated in the queue by a context change. You can address these queues directly in advanced user-defined functions.

No comments:

Archives