Code example for Document

Methods: appendChild, createElement

0
 
		StringWriter stringOut = new StringWriter();
		XMLSerializer serial2 = new XMLSerializer(stringOut, format);
		try { 
			serial2.asDOMSerializer();
			serial2.serialize(document);
		} catch (IOException e) {
			e.printStackTrace();
		} 
		 
		String serialized = stringOut.toString();
		//TODO this isn't nice at all! 
		serialized = serialized.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
		serialized = serialized.replace("<root>", "");
		serialized = serialized.replace("</root>", "");
 
		return serialized;
	} 
	 
	public Document toDoc(){
		doc = createNewDocument();
		allShapes = new LinkedList<JSONObject>();
		 
		createRoot(); 
		try { 
			createCanvas(); 
		} catch (DOMException e) {
			e.printStackTrace();
		} catch (JSONException e) {
			e.printStackTrace();
		} 
		 
		return doc;
	} 
	 
	protected void createRoot(){ 
		Element r = doc.createElement("root");
		/*r.setAttribute("xmlns:rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); 
		r.setAttribute("xmlns:admin", "http://webns.net/mvcb/"); 
		r.setAttribute("xmlns:doap", "http://usefulinc.com/ns/doap#"); 
		r.setAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/"); 
		r.setAttribute("xmlns:foaf", "http://xmlns.com/foaf/0.1/"); 
		r.setAttribute("xmlns:rdfs", "http://www.w3.org/2000/01/rdf-schema#");*/ 
		root = doc.appendChild(r);
	} 
	 
	protected void createCanvas() throws DOMException, JSONException{ 
		Node canvasNode = createShape(canvas);