fileNode.setAttribute("Size", Long.toString(files[fileIndex].size));
fileNode.setAttribute("size", Long.toString(files[fileIndex].size));
  public String ToXML()  {    DocumentBuilderFactory docBuilderFactory = null;    DocumentBuilder docBuilder = null;    Document document = null;        Element root;    Element fileInfo;    Element item;        // set up the objects we need to encode the flood data to XML    try     {      docBuilderFactory = DocumentBuilderFactoryImpl.newInstance();      docBuilder = docBuilderFactory.newDocumentBuilder();      document = docBuilder.newDocument();    }     catch(Exception e)     {      System.out.println("Error: " + e);      System.exit(0);    }        // create the root node    root = document.createElement("BitFlood");		    // create the fileinfo node and append it to the root    fileInfo = document.createElement("FileInfo");    root.appendChild(fileInfo);		    // add any tracker nodes    for(int trackerIndex = 0; trackerIndex < trackers.length; trackerIndex++)     {      if(trackers[trackerIndex] == null)      {        break;      }		        item = document.createElement("Tracker");      item.appendChild(document.createTextNode(trackers[trackerIndex]));      root.appendChild(item);    }        for(int fileIndex = 0; fileIndex < files.length; fileIndex++)     {      if(files[fileIndex] == null)      {        break;      }  		      Element fileNode = document.createElement("File");      fileNode.setAttribute("name", files[fileIndex].name); // FIXME: have to cleanse the filename to spec (unix)      fileNode.setAttribute("Size", Long.toString(files[fileIndex].size));      fileInfo.appendChild(fileNode);      for(int chunkIndex = 0; chunkIndex < files[fileIndex].chunks.length; chunkIndex++)      {      	Element chunkNode = document.createElement("Chunk");      	chunkNode.setAttribute("index", Long.toString(files[fileIndex].chunks[chunkIndex].index));      	chunkNode.setAttribute("hash", files[fileIndex].chunks[chunkIndex].hash);      	chunkNode.setAttribute("size", Long.toString(files[fileIndex].chunks[chunkIndex].size));      	chunkNode.setAttribute("weight", Long.toString(files[fileIndex].chunks[chunkIndex].weight));      	fileNode.appendChild(chunkNode);      }    }          // add the root node to the document    document.appendChild(root);  	    // write it all out    StringWriter  strWriter       = null;    XMLSerializer xmlSerializer   = null;    OutputFormat  outFormat       = null;    String result = null;    try     {      xmlSerializer = new XMLSerializer();      strWriter = new StringWriter();      outFormat = new OutputFormat();      outFormat.setEncoding("UTF-8");      outFormat.setVersion("1.0");      outFormat.setIndenting(true);      outFormat.setIndent(2);      outFormat.setLineWidth(0);            xmlSerializer.setOutputCharStream(strWriter);      xmlSerializer.setOutputFormat(outFormat);      xmlSerializer.serialize(document);            result = strWriter.toString();      strWriter.close();    }     catch (IOException ioEx)     {      System.out.println("Error: " + ioEx);      System.exit(0);    }        return result;  }