Creating new elements by using a JavaCompute node
You can use a JavaCompute node to create new elements.
About this task
Use the following methods in a JavaCompute node to create
new elements in a message tree:
- createElementAsFirstChild()
- createElementAsLastChild()
- createElementBefore()
- createElementAfter()
This example Java™ code
adds a new chapter element to the XML example given in Accessing elements in a message tree from a node:
MbElement root = outMessage.getRootElement();
MbElement document = root.getLastChild().getFirstChild();
MbElement chapter2 = document.createElementAsLastChild(MbElement.TYPE_NAME,"Chapter",null);
// add title attribute
MbElement title2 = chapter2.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE,
"title", "Message Flows");
This produces the following XML output: <document>
<chapter title="Introduction">
Some text.
</chapter>
<chapter title="Message Flows"/>
</document>