String searchResultToXml(FieldSearchResult result) {
    StringBuffer xmlBuf = new StringBuffer();

    xmlBuf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    xmlBuf.append("<result xmlns=\"http://www.fedora.info/definitions/1/0/types/\">\n");
    if ((result != null) && (result.getToken() != null)) {
      xmlBuf.append("  <listSession>\n");
      xmlBuf.append("    <token>" + result.getToken() + "</token>\n");
      if (result.getCursor() != -1) {
        xmlBuf.append("    <cursor>" + result.getCursor() + "</cursor>\n");
      }
      if (result.getCompleteListSize() != -1) {
        xmlBuf.append(
            "    <completeListSize>" + result.getCompleteListSize() + "</completeListSize>\n");
      }
      if (result.getExpirationDate() != null) {
        xmlBuf.append(
            "    <expirationDate>"
                + DateUtility.convertDateToString(result.getExpirationDate())
                + "</expirationDate>\n");
      }
      xmlBuf.append("  </listSession>\n");
    }
    xmlBuf.append("  <resultList>\n");

    if (result != null) {
      List<ObjectFields> fieldList = result.objectFieldsList();

      for (int i = 0; i < fieldList.size(); i++) {
        ObjectFields f = fieldList.get(i);
        xmlBuf.append("  <objectFields>\n");
        appendXML("pid", f.getPid(), xmlBuf);
        appendXML("label", f.getLabel(), xmlBuf);
        appendXML("state", f.getState(), xmlBuf);
        appendXML("ownerId", f.getOwnerId(), xmlBuf);
        appendXML("cDate", f.getCDate(), xmlBuf);
        appendXML("mDate", f.getMDate(), xmlBuf);
        appendXML("dcmDate", f.getDCMDate(), xmlBuf);
        appendXML("title", f.titles(), xmlBuf);
        appendXML("creator", f.creators(), xmlBuf);
        appendXML("subject", f.subjects(), xmlBuf);
        appendXML("description", f.descriptions(), xmlBuf);
        appendXML("publisher", f.publishers(), xmlBuf);
        appendXML("contributor", f.contributors(), xmlBuf);
        appendXML("date", f.dates(), xmlBuf);
        appendXML("type", f.types(), xmlBuf);
        appendXML("format", f.formats(), xmlBuf);
        appendXML("identifier", f.identifiers(), xmlBuf);
        appendXML("source", f.sources(), xmlBuf);
        appendXML("language", f.languages(), xmlBuf);
        appendXML("relation", f.relations(), xmlBuf);
        appendXML("coverage", f.coverages(), xmlBuf);
        appendXML("rights", f.rights(), xmlBuf);
        xmlBuf.append("  </objectFields>\n");
      }
    }
    xmlBuf.append("  </resultList>\n");
    xmlBuf.append("</result>\n");

    return xmlBuf.toString();
  }