Message brokers are intermediary programs that transform route messages between applications. Most brokers allow user defined logic to be executed during the processing of a message. One such embodiment allows PHP scripts to be executed in a broker. This publication explains how the familiar PHP array syntax can be used to build messages with repeating substructures.
Page 1 of 3
Use of array notation to build messages with repeating substructures
Message processing in a broker (or ESB) typically involves its transformation from one format to another to allow disparate applications to exchange data. The content of the input message is generally used to determine the content or destination of the output. Frequently, scripts are written in a programming language to specify the exact nature of this transformation processing. A parser is invoked by the system to translate the input message into a hierarchical (tree) structure representing the logical model of the message (e.g. DOM is a hierarchical representation of an XML document).
Current systems exist to create messages as the tree representations are being navigated. For example, the ESQL language in IBM * WebSphere * Message Broker supports the following syntax:
SET OutputRoot.XML.a.b.c = 'foo';
which will generate the following XML:
foo
The general rule is that the interpreter will attempt to navigate the tree in accordance with the path syntax, but if an element doesn't exist in the tree, then it is created. However, if we wish to create a second
element as a sibling of the existing one, there is no existing way to specify this as a new element rather than the existing one using a path syntax. For example the following code:
SET OutputRoot.XML.a.b.c = 'foo';
SET OutputRoot.XML.a.b.c = 'bar';
would generate the following XML:
bar
This changes the value of the existing
element rather than creating a new one.
Existing solutions to this would be to navigate to the element, obtain a reference (pointer) to this element and then explicitly call a function to create this second element. The proposed solution would reduce the amount of user code required to achieve the same result.
This solution proposes a mechanism for utilising the array building syntax of a scripting language to be applied to element objects enabling multiple repeating su...