/** Writes the data provenance into xml formatted file */
  public void writeXML() throws IOException {
    FileWriter fw;
    if (file.exists() == true) {
      file.delete();
      file = new File(fileDir + File.separator + fileName);
    }

    try {

      fw = new FileWriter(file);
      bw = new BufferedWriter(fw);

      Vector<XMLAttributes> atVector = new Vector<XMLAttributes>();

      bw.write(XML_HEADER);
      bw.newLine();
      bw.write(DATA_PROVENANCE);
      bw.newLine();

      openTag("provenance", true);

      int numEntries = pHolder.size();

      ProvenanceEntry entry;

      for (int i = 0; i < numEntries; i++) {
        entry = pHolder.elementAt(i);

        openTag("processStep", true);

        atVector.add(new XMLAttributes("version", entry.getMipavVersion()));
        this.closedTag("program", entry.getProgramName(), atVector);

        atVector.add(new XMLAttributes("inputs", entry.getProgramInputs()));
        closedTag("programArguments", entry.getAction(), atVector);

        closedTag("timeStamp", entry.getTimeStamp());

        closedTag("user", entry.getUser());

        closedTag("hostName", entry.getHostName());

        closedTag("architecture", entry.getArchitecture());

        atVector.add(new XMLAttributes("version", entry.getPlatformVersion()));
        closedTag("platform", entry.getPlatform(), atVector);

        atVector.add(new XMLAttributes("version", entry.getJavaVersion()));
        closedTag("compiler", "java", atVector);

        openTag("processStep", false);
      }

      openTag("provenance", false);
      bw.close();
    } catch (Exception e) {
      System.err.println("CAUGHT EXCEPTION WITHIN writeXML() of FileDataProvenance");
      e.printStackTrace();
    }
  }
  private void tidyUnicode(String filename) {
    FileInputStream in = null;
    FileOutputStream out = null;
    InputStreamReader reader = null;
    OutputStreamWriter writer = null;
    File f0 = new File(filename + "0");
    File f1 = new File(filename);
    f1.renameTo(f0);
    try {
      in = new FileInputStream(f0);
      reader = new InputStreamReader(in);
      out = new FileOutputStream(f1);
      writer = new OutputStreamWriter(out);
      UTF8Tidy u = new UTF8Tidy(reader, writer);
      u.execute();
    } catch (Exception e) {
      {
      } // System.out.println("e: " + e ); }

    } finally {
      try {
        reader.close();
        writer.close();
      } catch (Exception ex) {
        ex.printStackTrace();
      }
      f0.delete();
    }
  }