public Table(String name, List<Column> columns) throws NameFormatException, Exception{
		
		this.name = name;
		this.columns = new HashMap<String, Column>();
		
		if(!checkValidTableName(name)) //must start with a letter and have a minimum of two characters
			throw new NameFormatException("a-z, A-Z, 0-9. The name must also start with a letter", "The name " + name + " is not valid."); 
		if(columns == null && columns.size() == 0)
			throw new Exception("You must specify atleast one column.");
		
		File xml = new File("Databases/" + name + ".xml");
		
		if(xml.exists()){ //empty the file if it exists
		    try {
		    	FileChannel outChan = new FileOutputStream(xml, true).getChannel();
				outChan.truncate(0);
				outChan.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		Element rootElement = new Element("table");
		rootElement.setAttribute("name", name);
		rootElement.setAttribute("nextIndex", "1");
		this.nextIndex = 1;
		Document table = new Document(rootElement);
		
		boolean indexFound = false;
		Element columnList = new Element("columns");
		for(Column column : columns){
			this.columns.put(column.getName(), column);
			Element col = new Element("column");
			col.setAttribute("name", column.getName());
			col.setAttribute("type", column.getType().toString());
			if(column.isIndex()){
				if(indexFound)
					throw new Exception("There can't be two indexes.");
				col.setAttribute("index", "index");
				this.indexColumn = column.getName();
			}
			columnList.addContent(col);
		}
		if(!indexFound){ //There must always be an index
			Element indexCol = new Element("column");
			indexCol.setAttribute("name", "index");
			indexCol.setAttribute("index", "index");
			indexCol.setAttribute("type", Column.Type.INT.toString());
			columnList.addContent(indexCol);
			Column indexColItem = new Column("index", Column.Type.INT);
			indexColItem.setIndex(true);
			this.indexColumn = "index";
			this.columns.put("index", indexColItem);
		}
		rootElement.addContent(columnList);
		
		rootElement.addContent(new Element("rows"));
		
		XMLOutputter xmlOutput = new XMLOutputter();
		 
		// display nice nice
		xmlOutput.setFormat(Format.getPrettyFormat());
		try {
			xmlOutput.output(table, new FileWriter(xml));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}