
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;


import java.util.ArrayList;
import java.util.List;

import org.jdom.output.*;
import org.jdom.Attribute;
import org.jdom.Document;			
import org.jdom.Element;			
import org.jdom.JDOMException;		
import org.jdom.input.SAXBuilder;	

public class WriteDishwasherRecipe {

	public void WriteXML(List<Recipe> myList)throws JDOMException, FileNotFoundException{
		
		FileOutputStream file = new FileOutputStream("Recipes\\Recipe1.xml");
		XMLOutputter out = new XMLOutputter();
		Document doc=new Document();
    	Element recipe=new Element("Recipe");

    	int i=0;
	    try {
    		doc.setRootElement(recipe);
	    	for(i=0 ;i<myList.size();i++){
	    		Element step = new Element("Step");
	    		step.setAttribute(new Attribute("number", Integer.toString(i+1)));
	    		step.addContent(new Element("Parameter").setText(myList.get(i).Parameter));
	    		step.addContent(new Element("Value").setText(Double.toString(myList.get(i).Value))); 
	    		doc.getRootElement().addContent(step);
	    	}
	    	out.output(doc, file);
	    }
	    catch (IOException e) {
	      System.err.println(e);
	    }
	}
}
