Compress if space is a problem
  //output
  OutputStream fout    = new FileOutputStream("data.xml.gz");
  OutputStream out     = new GZipOutputStream(fout);
  OutputFormat format  = new OutputFormat(document);
  XMLSerializer output = new XMLSerializer(out, format);
  output.serialize(doc);
 
  // input
  InputStream fin = new FileInputStream("data.xml.gz");
  InputStream in  = new GZipInputStream(fin);
  DocumentBuilderFactory factory
    = DocumentBuilderFactory.newInstance();  
  DocumentBuilder parser = factory.newDocumentBuilder();
  Document doc = parser.parse(in); S
  // work with the document...