public void write(VariableMap vars, File target) {
		this.vars = vars;
		
		DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
		dbfac.setValidating(false);
		dbfac.setNamespaceAware(true);

		DocumentBuilder docBuilder;
		try {
			docBuilder = dbfac.newDocumentBuilder();
			//docBuilder.setErrorHandler(lastErrors);

			doc = docBuilder.newDocument();

			writeRoot();

			//Write XML
			File f = target;
			TransformerFactory transfac = TransformerFactory.newInstance();
			Transformer trans = transfac.newTransformer();
			DOMSource source = new DOMSource(doc);
			OutputStream fos = new FileOutputStream(f);
			StreamResult result = new StreamResult(fos);
			trans.transform(source, result);
            fos.close();
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
		} catch (TransformerConfigurationException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (TransformerException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}