Chunk chunk = (Chunk) chunkiter.nextElement();
Chunk chunk = (Chunk) chunkiter.next();
  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    Enumeration trackeriter = trackers.elements();    for ( ; trackeriter.hasMoreElements(); )    {      TrackerInfo tracker = (TrackerInfo) trackeriter.nextElement();      item = document.createElement( "Tracker" );      item.setAttribute( "host", tracker.host );      item.setAttribute( "port", Integer.toString( tracker.port) );      root.appendChild( item );    }    Enumeration fileiter = files.elements();    for ( ; fileiter.hasMoreElements(); )    {      TargetFile file = (TargetFile) fileiter.nextElement();      Element fileNode = document.createElement( "File" );      fileNode.setAttribute( "name", file.name ); // FIXME: have to cleanse the filename to spec (unix)      fileNode.setAttribute( "size", Long.toString( file.size ) );      fileInfo.appendChild( fileNode );      Enumeration chunkiter = file.chunks.elements();      for ( ; chunkiter.hasMoreElements(); )      {        Chunk chunk = (Chunk) chunkiter.nextElement();        Element chunkNode = document.createElement( "Chunk" );        chunkNode.setAttribute( "index", Long.toString( chunk.index ) );        chunkNode.setAttribute( "hash", chunk.hash );        chunkNode.setAttribute( "size", Long.toString( chunk.size ) );        chunkNode.setAttribute( "weight", Long.toString( chunk.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;  }