以下 Java 代码示例向
从 JavaCompute 节点访问消息树中的元素中给出的 XML 示例添加新的 chapter 元素:
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");
这段代码生成以下 XML 输出:
<document>
<chapter title="Introduction">
某些文本。
</chapter>
<chapter title="Message Flows"/>
</document>