public File encode(Serializable structure, File file, Map parameters) {
		Transducer transducer = null;
		try {
			transducer = TransducerFactory.getTransducer(structure);
            
            /*
             * If we are saving a pumping lemma, the associated structure would
             * actually be a pumping lemma chooser. Thus, we have to get the
             * lemma from the chooser.
             */
            Document dom;
            if(structure instanceof gui.pumping.PumpingLemmaChooser)
                dom = transducer.toDOM(((gui.pumping.PumpingLemmaChooser)structure).getCurrent());
            else
                dom = transducer.toDOM(structure);
            
//			Document dom = transducer.toDOM(structure);    // original line
            
			DOMPrettier.makePretty(dom);
			Source s = new DOMSource(dom);
			Result r = new StreamResult(file);
			Transformer t = TransformerFactory.newInstance().newTransformer();
			t.transform(s, r);
			return file;
		} catch (IllegalArgumentException e) {
			throw new EncodeException(
					"No XML transducer available for this structure!");
		} catch (TransformerConfigurationException e) {
			throw new EncodeException("Could not open file to write!");
		} catch (TransformerException e) {
			throw new EncodeException("Could not open file to write!");
		}
	}