/**
   * Appends a field.
   *
   * @param comment
   */
  private void emitField(DocComment comment) {
    xml.append("\n<field name='");
    xml.append(comment.getName());
    xml.append("' fullname='");
    xml.append(comment.getFullname());
    xml.append("' type='");
    String type = comment.getVartype();
    if (type != null) xml.append(comment.getVartype());
    xml.append("' isStatic='");
    xml.append(comment.isStatic());
    xml.append("' isConst='");
    xml.append(comment.isConst());
    xml.append("' ");
    String defaultValue = comment.getDefaultValue();
    if (defaultValue != null) {
      xml.append("defaultValue='");

      try {
        Pattern pattern = Pattern.compile("\\p{Cntrl}");
        Matcher matcher = pattern.matcher(defaultValue);
        defaultValue = matcher.replaceAll("");
      } catch (Exception ex) {
      }

      xml.append(defaultValue);
      xml.append("' ");
    }
    xml.append(">");

    String desc = comment.getDescription();
    if (desc != null) appendTag("description", comment.getDescription());
    emitTags(comment.getAllTags());

    if (comment.getMetadata() != null) emitMetadata(comment.getMetadata());
    xml.append("\n</field>");
  }
  /**
   * Appends a function
   *
   * @param comment
   */
  private void emitFunction(DocComment comment) {
    xml.append("\n<method name='");
    xml.append(comment.getName());
    xml.append("' fullname='");
    xml.append(comment.getFullname());
    xml.append("' ");
    xml.append("isStatic='");
    xml.append(comment.isStatic());
    xml.append("' ");
    xml.append("isFinal='");
    xml.append(comment.isFinal());
    xml.append("' ");
    xml.append("isOverride='");
    xml.append(comment.isOverride());
    xml.append("' ");

    String[] param_names = comment.getParamNames();
    if (param_names != null) {
      xml.append(" param_names='");
      for (int i = 0; i < param_names.length; i++) {
        String pname = param_names[i];
        if (pname != null) {
          if (i != 0) xml.append(";");
          xml.append(pname);
        }
      }
      xml.append("'");

      String[] param_types = comment.getParamTypes();
      xml.append(" param_types='");
      for (int i = 0; i < param_types.length; i++) {
        String ptype = param_types[i];
        if (ptype != null) {
          if (i != 0) xml.append(";");
          xml.append(ptype);
        }
      }
      xml.append("'");

      String[] param_defaults = comment.getParamDefaults();
      xml.append(" param_defaults='");
      for (int i = 0; i < param_defaults.length; i++) {
        String pdefa = param_defaults[i];
        if (pdefa != null) {
          if (i != 0) xml.append(";");
          xml.append(pdefa);
        }
      }
      xml.append("'");
    }

    xml.append(" result_type='");
    xml.append(comment.getResultType());
    xml.append("'>");

    String desc = comment.getDescription();
    if (desc != null) appendTag("description", comment.getDescription());
    emitTags(comment.getAllTags());

    if (comment.getMetadata() != null) emitMetadata(comment.getMetadata());
    xml.append("\n</method>");
  }
  /**
   * Appends a class or interface
   *
   * @param comment
   */
  private void emitClass(DocComment comment) {
    String tagName = (comment.getType() == DocComment.CLASS) ? "classRec" : "interfaceRec";
    xml.append("\n<");
    xml.append(tagName);
    xml.append(" name='");
    xml.append(comment.getName());
    xml.append("' fullname='");
    xml.append(comment.getFullname());
    String sourcefile = comment.getSourceFile();
    if (sourcefile != null) {
      xml.append("' sourcefile='");
      xml.append(sourcefile);
    }
    xml.append("' namespace='");
    xml.append(comment.getNamespace());
    xml.append("' access='");
    xml.append(comment.getAccess());
    xml.append("' ");
    if (comment.getType() == DocComment.INTERFACE) {
      String[] baseClasses = comment.getBaseclasses();
      if (baseClasses != null) {
        xml.append("baseClasses='");
        for (int i = 0; i < baseClasses.length; i++) {
          String baseclass = baseClasses[i];
          if (baseclass != null) {
            if (i != 0) xml.append(";");
            xml.append(baseclass);
          }
        }
        xml.append("' ");
      }
    } else {
      xml.append("baseclass='");
      xml.append(comment.getBaseClass());
      xml.append("' ");
      String[] interfaces = comment.getInterfaces();
      if (interfaces != null) {
        xml.append("interfaces='");
        for (int i = 0; i < interfaces.length; i++) {
          String inter = interfaces[i];
          if (inter != null) {
            if (i != 0) xml.append(";");
            xml.append(inter);
          }
        }
        xml.append("' ");
      }
    }
    xml.append("isFinal='");
    xml.append(comment.isFinal());
    xml.append("' ");
    xml.append("isDynamic='");
    xml.append(comment.isDynamic());
    xml.append("' ");
    xml.append(">");

    String desc = comment.getDescription();
    if (desc != null) appendTag("description", comment.getDescription());
    emitTags(comment.getAllTags());

    if (comment.getMetadata() != null) emitMetadata(comment.getMetadata());
    xml.append("\n</");
    xml.append(tagName);
    xml.append(">");
  }