org.dom4j.Element pubsubElement = result.setChildElement("pubsub", "http://jabber.org/protocol/pubsub");
org.dom4j.Element itemsElement = pubsubElement.addElement("items");
itemsElement.addAttribute("node", PEPActivityHandler.NODE);
for (ActivityMessage message : messages) {
Element entryElement = (Element) domDocument.appendChild(domDocument.createElementNS(Atom.NAMESPACE, Atom.ENTRY_ELEMENT));
writer.write(message.getActivity(), entryElement);
domDocument.removeChild(entryElement);
org.dom4j.Element itemElement = itemsElement.addElement("item");
itemElement.addAttribute("id", message.getActivity().getId());
itemElement.add((org.dom4j.Element) entryElement);