public Element toElement() {
		cleanTableFrom();
		DocumentFactory factory = DocumentFactory.getInstance();
		Element root = factory.createElement(DbSchema.DBSELECT_FIELD);
		root.addAttribute(DbSchema.OFFSET_ATTRIBUTE, Integer.toString(offset));
		root.addAttribute(DbSchema.LIMIT_ATTRIBUTE, Integer.toString(limit));
		
		if (selected.isEmpty()) {
			return root;
		}
		Element select = factory.createElement(DbSchema.SELECTED_FIELD);
		for (DbField field : selected) {
			Element efield = factory.createElement(DbSchema.FIELD_FIELD);
			efield.setText(field.toString());
			select.add(efield);
		}
		root.add(select);
		Element from = factory.createElement(DbSchema.FROM_FIELD);
		for (DbTable table : fromTables.values()) {
			Element efield = factory.createElement(DbSchema.TABLE_FIELD);
			efield.setText(table.toString());
			from.add(efield);
		}
		root.add(from);
		if (! conditions.isEmpty()) {
			Element econd = factory.createElement(DbSchema.CONDITIONS_FIELD);
			for (DbCondition condition : conditions) {
				Element efield = condition.toElement();
				econd.add(efield);
			}
			root.add(econd);
		}
		if (! orderByAsc.isEmpty()) {
			Element eorder = factory.createElement(DbSchema.ORDERASC_FIELD);
			for (DbField field : orderByAsc.values()) {
				Element efield = factory.createElement(DbSchema.FIELD_FIELD);
				efield.setText(field.toString());
				eorder.add(efield);
			}
			root.add(eorder);
		}
		if (! orderByDesc.isEmpty()) {
			Element eorder = factory.createElement(DbSchema.ORDERDESC_FIELD);
			for (DbField field : orderByDesc.values()) {
				Element efield = factory.createElement(DbSchema.FIELD_FIELD);
				efield.setText(field.toString());
				eorder.add(efield);
			}
			root.add(eorder);
		}
		return root;
	}