public void writeModel(OutputStream output, CourseModel model)
			throws IOException {
		try {
			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
			DocumentBuilder db = dbf.newDocumentBuilder();
			Document dom = db.newDocument();

			Element root = dom.createElement("StaticData");
			dom.appendChild(root);

			// Categories
			Element group = dom.createElement("Categories");
			root.appendChild(group);
			ArrayList<DescRec> list = new ArrayList<DescRec>();
			for (Source source : Source.values())
				list.addAll(model.getCategories(source));
			Collections.sort(list);
			for (DescRec rec : list) {
				group.appendChild(makeDescNode(rec, dom));
			}

			// Universities
			list = new ArrayList<DescRec>();
			for (Source source : Source.values())
				list.addAll(model.getUniversities(source));
			Collections.sort(list);
			group = dom.createElement("Universities");
			root.appendChild(group);
			for (DescRec rec : list) {
				group.appendChild(makeDescNode(rec, dom));
			}

			// Courses
			group = dom.createElement("Classes");
			root.appendChild(group);
			ArrayList<CourseRec> list2 = new ArrayList<CourseRec>();
			for (Source source : Source.values())
				list2.addAll(model.getCourses(source));
			Collections.sort(list2, new Comparator<CourseRec>() {
				@Override
				public int compare(CourseRec o1, CourseRec o2) {
					return o1.getId().compareTo(o2.getId());
				}
			});
			for (CourseRec rec : list2) {
				group.appendChild(makeCourseNode(rec, dom, model));
			}

			try {
				Transformer tr = TransformerFactory.newInstance()
						.newTransformer();
				tr.setOutputProperty(OutputKeys.INDENT, "yes");
				tr.setOutputProperty(OutputKeys.METHOD, "xml");
				tr.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
				tr.setOutputProperty(
						"{http://xml.apache.org/xslt}indent-amount", "2");

				tr.transform(new DOMSource(dom), new StreamResult(output));

			} catch (TransformerException te) {
				throw new IOException(te);
			}
		} catch (ParserConfigurationException pce) {
			System.out
					.println("UsersXML: Error trying to instantiate DocumentBuilder "
							+ pce);
		}
	}