code: public Element collectionToElement() {
          final Collection collection = this;
          final Element element = new Element("collection", AtomService.ATOM_PROTOCOL);
          element.setAttribute("href", collection.getHref());
  
          final Element titleElem = new Element("title", AtomService.ATOM_FORMAT);
          titleElem.setText(collection.getTitle());
          if (collection.getTitleType() != null && !collection.getTitleType().equals("TEXT")) {
              titleElem.setAttribute("type", collection.getTitleType(), AtomService.ATOM_FORMAT);
          }
          element.addContent(titleElem);
  
          // Loop to create <app:categories> elements
          for (final Object element2 : collection.getCategories()) {
              final Categories cats = (Categories) element2;
              element.addContent(cats.categoriesToElement());
          }
  
          for (final Object element2 : collection.getAccepts()) {
              final String range = (String) element2;
              final Element acceptElem = new Element("accept", AtomService.ATOM_PROTOCOL);
              acceptElem.setText(range);
              element.addContent(acceptElem);
          }
  
          return element;
      }
docs: Serialize an AtomService.Collection into an XML element