WebSphere Message Broker, Version 8.0.0.7
Operating Systems: AIX, HP-Itanium, Linux, Solaris, Windows, z/OS
See information about the latest product version
See information about the latest product version
Creating new elements by using a JavaCompute node
You can use a JavaCompute node to create new elements.
Use the following methods in a JavaCompute node to create
new elements in a message tree:
- createElementAsFirstChild()
- createElementAsLastChild()
- createElementBefore()
- createElementAfter()
- createElement...(int type)
- Creates a blank element of the specified type. Valid generic
types are:
- MbElement.TYPE_NAME. This type of element has only a name, for example an XML element.
- MbElement.TYPE_VALUE. This type of element has only a value, for example XML text that is not contained in an XML element.
- MbElement.TYPE_NAME_VALUE. This type of element has both a name and a value, for example an XML attribute.
- createElement...(int type, String name, Object value)
- Method for setting the name and value of the element at creation time.
- createElement...(String parserName)
- A special form of createElement...() that is only used to create top-level parser elements.
This example Java™ code
adds a new chapter element to the XML example given in Accessing elements in a message tree from a JavaCompute 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>