Chapter 7. Scenario: Data transformation and security 211
The transformation is done using XPath (Example 7-12).
Example 7-12 XPath transformation on a JavaCompute node: Transform_TDS code
...
// Prepare the MQMD header if it doesn't exist //
BankUtils.createMQMD(outRootElement);
// Creates the parser //
MbElement parser = outRootElement.createElementAsLastChild("MRM");
// Creates the data message that will be used by the message set //
MbElement dataElement =
parser.createElementAsLastChild(MbElement.TYPE_NAME, "data", null);
// Define the TDS element structure using XPath //
MbXPath xpName =
new MbXPath("/?$Name[set-value($client_name)]", dataElement);
MbXPath xpLName =
new MbXPath("/?$LastName[set-value($client_lname)]",
dataElement);
MbXPath xpSSN =
new MbXPath("/?$SSN[set-value($ssn)]", dataElement);
MbXPath xpAddr =
new MbXPath("/?$Address[set-value($addr)]", dataElement);
// Populate the variables defined above //
xpName.assignVariable("client_name", ...);
xpLName.assignVariable("client_lname", ...);
xpSSN.assignVariable("ssn", ...);
xpAddr.assignVariable("addr", ...);
// Evaluate the XPath definitions //
outMessage.evaluateXPath(xpName);
outMessage.evaluateXPath(xpLName);
outMessage.evaluateXPath(xpSSN);
outMessage.evaluateXPath(xpAddr);
...
The following actions occur in the Transform_TDS code:
1. The code creates the root message structure that is expected by the
MessageSet /Root/MRM/data/.
2. The XPath expressions are defined by using the “data” element in the
message as the root element for the new message structure (set in the
dataElement variable). The second argument of the MbXpath constructor
defines dataElement as the root element.