Element () { Element element = new Element("state"); for (Map.Entry<String, LinkedList<String>> entry : myMap.entrySet()) { Element keyElement = new Element(KEY_ELEMENT_NAME); keyElement.setAttribute(NAME_ATTR, entry.getKey()); for (String recent : entry.getValue()) { keyElement.addContent(new Element(RECENT_ELEMENT_NAME).setAttribute(NAME_ATTR, recent)); } element.addContent(keyElement); } return element; }