TM Design Tool is primarily targeted at data-oriented XML using statically typed transforms between named nodes. There are a number of advantages to this approach, which, incidentally, is the approach of all modern languages such as C++,C# or Java, the general belief in programming circles being that greater type safety leads to greater reliability. However, to cater for document oriented XML and to provide a more flexible approach to typed transformations, TM Design Tool also supports operations on untyped data.
SML allows access to untyped nodes of any type. This allows the construction of maps to perform deep copies, to handle unexpected XML data and to provide partial deep copies with exceptional handling of elements of interest. It also provides access to non-text and element nodes.
Untyped access is very easy to set up. Simply add relationships to one the untyped nodes the system makes available and use these in the transform.
Note that although you may appear to be using "untyped" arrays of objects,
the TM Design Tool GUI understands both casting and coercion in SML.
Thus in the following example both the 'CAR' and 'VEHICLE' elements must exist
in the appropriate models and have a relationship of an attribute with the name
'colour.'
anArrayofAnyChildElements[idx]{<VEHICLE>}.colour := {<CAR>}anotherArrayofAnyChildElements[2].colour;Here the{VEHICLE} on the left hand side is an example of coercion. It tells
the system that we want to create a concrete VEHICLE element node rather than an
abstract node. Indeed it is an error to attempt to create an abstract node.
{CAR} on the right hand side is an example of casting. It tells the
TM Design Tool that the object we get back is to be treated as a CAR
object - in other words it will have the attributes and relationships of a CAR.
Casting always 'succeeds' but if object cast is of the wrong type then all the
values are taken from the item that is present - thus those items may come back
as null or be of the wrong type. It is very easy to check the type with an
IF
statement and $name pseudo-attribute.
IF (anotherArrayofAnyChildElements.[2].$name='CAR') THEN
...
Because TM Design Tool understands both casting and coercion, if either attribute is missing then the TM Design Tool will complain just as if typed named elements are in use. However, be aware that using untyped nodes dynamically may side step TM Design Tool 's methods for ensuring that the result conform with the schema or DTD.
The above example can be extended to include the use of local variable. For example
LOCAL
var : string;
END_LOCAL;
var := 'MX5'
anArrayofAnyChildElements[idx]{$var}.colour := {<CAR>}anotherArrayofAnyChildElements[2].colour;
wIll result in an MX5 node being created. Note the use of
the $ before the var. This tells Transformation
Manger to use the value in the variable. If the $ is excluded, Transformation
Manager would create a Var node.