void (Element parentElement, Collection<String> collection, String collectionName, String itemName) { if (!collection.isEmpty()) { Element child = parentElement.getChild(getTagName()); if (child == null) { child = new Element(getTagName()); parentElement.addContent(child); } Element element = new Element(collectionName); for (String item : collection) { element.addContent(new Element(itemName).setAttribute(COLLECTION_ITEM_ATTRIBUTE, item)); } child.addContent(element); } }