/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package xmlpackage;


import applications.Trip;
import java.io.FileWriter;
import java.util.Enumeration;
import java.util.Vector;
import mdot.Main;
import org.jdom.*;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import structures.ChargesEntry;

/**
 *
 * @author student
 */
public class ChargesWriter {

 public static void writeToFile(Vector<ChargesEntry> charges)
    {

      
        Element chargesElement = new Element("charges");
        Document myDocument = new Document(chargesElement);

        Enumeration en = charges.elements();


        while(en.hasMoreElements())
        {

            Element charge = new Element("charge");

            ChargesEntry chargeData = (ChargesEntry)en.nextElement();

            Element date = new Element("date");
               date.addContent(chargeData.getDate());

            Element type = new Element("type");
               type.addContent(chargeData.getType());

            Element lat = new Element("lat");
                lat.addContent(String.valueOf(chargeData.getLat()));

            Element lon = new Element("lon");
                lon.addContent(String.valueOf(chargeData.getLon()));

            Element price = new Element("price");
                price.addContent(String.valueOf(chargeData.getPrice()));
            

            charge.addContent(date);
            charge.addContent(type);
            charge.addContent(lat);
            charge.addContent(lon);
            charge.addContent(price);
           
           
            chargesElement.addContent(charge);
        }

       try {

            FileWriter writer = new FileWriter(Main.wallet);

            org.jdom.output.Format f = Format.getPrettyFormat();
            XMLOutputter outputter = new XMLOutputter(f);
            outputter.output(myDocument, writer);

            writer.close();
            } catch (java.io.IOException e) {
            e.printStackTrace();
        }

    }

}