Configuring a generic type in the local environment tree by using the Cast function
You can use the Cast function to define variables in a message map that are defined in the local environment tree, such as in the Variables folder.
About this task
In this example,
Variablesis a generic element, and you must define the required elements in it for each value_name. You can also set values in the output local environment,
Destination.specific_node, to override the behavior of a following node. For example:
- For routing in the message flow, the map could
- To set a parameter to issue a REST
In this case,
Parametersis a generic element, and you must define the required elements in it for each parameter_name.
To configure the local environment tree Variables or other generic element, so that you can use its elements as part of your transformations, complete the following steps:
- If you already have the required element defined
in a message model, such as an XML schema, DFDL
schema, JSON schema, or Swagger document, omit this step and
go to step 2; otherwise, complete this step to create a model to define
Create a schema file in your application, integration service, or library to define the elements of the local environment tree Variables folder and their type:
- In the Application Development view, select . Click Next.
- Select Create an empty XML schema file, I will model my data using the XML schema
editor, and then click Next.
- Create an XSD file YourLExsdFileName.xsd, where
YourLExsdFileName is the name of the file that contains the local environment
variables folder message model. Then, click Finish.
- The XSD file opens in a new tab where you use the XML Schema
editor to define your variables and their types.
For example, you can define the following schema:
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="Country" type="xsd:string"/> <xsd:element name="CountryCode" type="xsd:integer"/> </xsd:schema>Note: You can define the local environment variables in a message flow node by using ESQL or Java™. Namespaces is not defined. For this reason, the schema is also defined without a namespace declaration.
- Use the Cast function to define
the local environment variables in the message map so they are visible under
the Variables folder in the map. Complete the
following steps to cast the any element to
a variable and its type in the output local environment tree:
- Right-click the any element, and then select
- In the Type Selection window, select a type, for example
Country, and then click OK. Note: Do not cast to an XML type that uses attributes. The data in the local environment tree is stored by using a generic parser and does not have specific field types set, (see XMLNSC: Using field types). In particular, if you copy data from an XMLNSC tree into the local environment tree, the field type that defines the element or attribute type is not preserved. If you model the data to be an attribute, the map attempts to access the data by using an XPath expression that matches data elements that have the field type that is specified in the XMLNSC tree, and so the data is not read.
- Right-click the any element, and then select Cast.
You have defined one local environment variable that can be used by other message flow nodes in your message flow for routing or filtering.
You can see the element Country under the local environment Variables folder in the message map.
If you set in an ESQL compute node two simple fields within the Variables folder of the Local Environment tree by using the following code:
SET Outputlocal environment.Variables.dec = 10.1; SET Outputlocal environment.Variables.str = 'Some text';
To access these fields in a Mapping node by using the Cast function, you must create a schema file in your integration solution to define the elements and their type. Note that since the ESQL is not using any namespace to qualify these elements, the schema is also defined without a namespace declaration:
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="dec" type="xsd:decimal"/> <xsd:element name="str" type="xsd:string"/> </xsd:schema>
Once the schema file is saved, you can then select the any element under the Variables section in the Local Environment tree, and use the context menu action Cast to add a Mapping cast for each of the elements "dec" and "str" that are required in the message map. For more information, see Mapping xsd:any on an input or output message.
What to do next
Define transforms between the input local environment tree and the output local environment tree. For more information, see Specifying a transform (mapping operation) and Transform types in the Graphical Data Mapping editor.