public void convertToXml(
      List<ReportResultData> reportData, List<Object> result, Map<String, String> xmlMap)
      throws XPathExpressionException, ParserConfigurationException {

    Document document = newEmptyDocument();
    Map<String, String> lastSubIdMap = dao.retrieveLastValidSubscriptionIdMap();

    for (ReportResultData data : reportData) {
      Element row = document.createElement("row");
      for (int columnIndex = 0; columnIndex < data.getColumnCount(); columnIndex++) {
        String columnName = data.getColumnName().get(columnIndex);
        Object value = data.getColumnValue().get(columnIndex);
        Element node = document.createElement(columnName.toUpperCase());
        if (value != null) {

          if (columnName.equalsIgnoreCase("SUBSCRIPTIONID")) {
            String id = lastSubIdMap.get(value);
            if (id != null) {
              value = id;
            }
          } else if (columnName.equalsIgnoreCase("PRODUCTID")) {
            String productId = (String) value;
            String[] split = productId.split("#");
            value = split[0];
          } else if (dateColumnNames.contains(columnName.toUpperCase()) && value instanceof Long) {
            Long dateFieldValue = (Long) value;

            value =
                DateConverter.convertLongToDateTimeFormat(
                    dateFieldValue.longValue(),
                    TimeZone.getDefault(),
                    DateConverter.DTP_WITHOUT_MILLIS);
          }
          readColumnValue(document, xmlMap, columnName, value, data, columnIndex, node);
        } else {
          int columnType = data.getColumnType().get(columnIndex).intValue();
          if (columnType == Types.VARCHAR
              || columnType == Types.CLOB
              || (columnType == Types.BIGINT
                  && dateColumnNames.contains(columnName.toUpperCase()))) {
            node.appendChild(document.createTextNode(""));
          } else {
            node.appendChild(document.createTextNode("null"));
          }
        }
        row.appendChild(node);
      }
      result.add(row);
    }
  }
  private void readColumnValue(
      Document doc,
      Map<String, String> xmlFieldXPaths,
      String columnName,
      Object value,
      ReportResultData reportData,
      int index,
      Element node)
      throws XPathExpressionException {
    if ("RESULTXML".equalsIgnoreCase(columnName)
        || "PROCESSINGRESULT".equalsIgnoreCase(columnName)) {
      Document columnValueAsDoc = parseXML((String) reportData.getColumnValue().get(index));

      if (xmlFieldXPaths.containsKey(columnName.toLowerCase())) {
        String xpathEvaluationResult =
            XMLConverter.getNodeTextContentByXPath(
                columnValueAsDoc, xmlFieldXPaths.get(columnName));
        // don't store null values but empty strings instead, to ensure
        // proper display on client side
        if (xpathEvaluationResult == null) {
          xpathEvaluationResult = "";
        }
        node.appendChild(doc.createTextNode(xpathEvaluationResult));
      } else {
        appendXMLStructureToNode(node, columnValueAsDoc);
      }
    } else {
      node.appendChild(doc.createTextNode(value.toString()));
    }
  }