Document doc = st.createDocument();
Element root = createChildElement(aggregateElementName, doc);
root.setAttribute(countAttribute, Integer.toString(messages.length));
for (int i = 0; i < messages.length; i++) {
if (messages[i] != null) {
Element elem = st.toDOMElement(messages[i]);
if (messageElementName != null) {
Element msg = createChildElement(messageElementName, root);
msg.setAttribute(indexAttribute, Integer.toString(i));
msg.appendChild(doc.importNode(elem, true));
} else {