docs: public static void createXMLRecord(DocumentBuilder stringdb, Record record, Document doc, Element elRoot)
          throws DBException
      {
          CounterField fldCounter = (CounterField)record.getCounterField();
          Element elRecord = null;
          Element elField = null;
          elRecord = doc.createElement(record.getTableNames(false));
          elRoot.appendChild(doc.createTextNode(NEWLINE + RECORDTAB));
          elRoot.appendChild(elRecord);
          String strObjectIDName = DBConstants.STRING_OBJECT_ID_HANDLE;
          String strObjectID = null;
          Object objID = record.getHandle(DBConstants.OBJECT_ID_HANDLE);
          if (fldCounter != null)
          {
              strObjectIDName = fldCounter.getFieldName();
              if (objID == null)  // ie., for a non-persistent object
                  objID = record.getHandle(DBConstants.BOOKMARK_HANDLE);
          }
          if (objID != null)
              strObjectID = objID.toString();
          if (strObjectID != null)
              if (fldCounter == record.getField(0))
                  elRecord.setAttribute(strObjectIDName, strObjectID);
          for (int i = 0; i < record.getFieldCount(); i++)
          {
              BaseField field = record.getField(i);
              if (field == fldCounter) if (strObjectID != null)
                  continue; // Not necessary to add counter field
              if (field instanceof UnusedField)
                  continue;   // Don't add this.
              elRecord.appendChild(doc.createTextNode(NEWLINE + FIELDTAB));
              elRecord.appendChild(elField = doc.createElement(field.getFieldName()));
              if (!field.isNull())
              {
                  String string = field.toString();
                  String type = TEXT;
                  if (field instanceof ObjectField)
                  {
                      string = XmlUtilities.encodeFieldData(field);
                      type = CDATA;
                      if ((string != null) && (string.length() > 0))
                          elField.setAttribute(ENCTYPE_PARAM, BINARYENCODING);
                  }
                  else if (field instanceof DateTimeField)
                  {
                  	string = XmlUtilities.encodeDateTime((DateTimeField)field);
                  }
                  else if ((field instanceof XmlField)
                      || (field instanceof XMLPropertiesField)
                      || (field instanceof HtmlField))
                  {
                      if ((string != null)
                          && (string.length() > 0))
                      {
                          type = XML;
                          String strXML = string;
                          boolean bNoRootNode = true;
                          if ((strXML.length() < 5)
                              || (!strXML.substring(0, 5).equalsIgnoreCase(XML_LEAD_LINE.substring(0, 5))))
                                  strXML = XML_LEAD_LINE + START_TEMP_TAG + strXML + END_TEMP_TAG;    // Always
                          else
                              bNoRootNode = false;
                          InputSource is = new InputSource(new StringReader(strXML));
                          Document fieldDoc = null;
                          boolean bError = false;
                          try {
                              fieldDoc = stringdb.parse(is);
                          } catch (SAXException ex) {
                              Utility.getLogger().info("Fallback to CData");
                              bError = true;
                          } catch (IOException ex) {
                              ex.printStackTrace();
                              bError = true;
                          }
                          if (!bError)
                          {   // Add the child nodes to this node (with type="XML")
                              Node element = fieldDoc.getDocumentElement();
                              Node node = doc.importNode(element, true);
                              int iCount = 0;
                              if (bNoRootNode)
                              {
                                  while (node.hasChildNodes())
                                  {
                                      Node child = node.getFirstChild();
                                      node.removeChild(child);
                                      elField.appendChild(child);
                                      iCount++;
                                      if (child.getNodeType() != Node.TEXT_NODE)
                                          iCount++;
                                  }
                              }
                              else
                              {
                                  elField.appendChild(node);
                                  iCount = 20;    // XML type
                              }
                              if (iCount > 1)     // For everthing except a single text node type=xml
                                  elField.setAttribute(TYPE_PARAM, XML_VALUE);    // A text field would have 1 element (not XML).
                          }
                          else
                          {
                              type = TEXT;
                              if (Utility.isCData(string))
                                  type = CDATA; // If not well-formed, just pass the string as CData.
                          }
                      }
                  }
                  else if (Utility.isCData(string))
                          type = CDATA;
                  if (type == TEXT)
                      elField.appendChild(doc.createTextNode(string));
                  else if (type == CDATA)
                      elField.appendChild(doc.createCDATASection(string));
              }
          }
          elRecord.appendChild(doc.createTextNode(NEWLINE + RECORDTAB));
      }