src/authoring/entities/data/EntitySaver.java
public void writeXML(Map<Class, Object[]> attributes, String fileName) throws TransformerFactoryConfigurationError, TransformerException {
		Document document = DOCUMENT_BUILDER.newDocument();
		Element root = document.createElement(DOCUMENT_TITLE);
		root.setAttribute("name", fileName);
		System.out.println("SAVING TO " + DataUtils.getGame());
		root.setAttribute("game", DataUtils.getGame());
		document.appendChild(root);
		for (Class compClass : attributes.keySet()) {
			// get rid of everything in front of the name itself
			String compName = compClass.getName().replace(COMPONENT_PREFIX, "");
			Element comp = document.createElement(compName);
			root.appendChild(comp);
			if (attributes.get(compClass).length == 0) {
				comp.appendChild(document.createTextNode(""));
			} else {
        			for (Object o : attributes.get(compClass)) {
        				comp.appendChild(document.createTextNode(String.valueOf(o)));
        			}
			}
		}
		Transformer t = TransformerFactory.newInstance().newTransformer();
		DOMSource ds = new DOMSource(document);
		StreamResult sr = new StreamResult(new File(FOLDER_PATH + fileName + XML_EXTENSION));
		t.transform(ds, sr);
		System.out.println("XML file created and saved to " + FOLDER_PATH + fileName);
	}
/**
	 * Writes the data given in a map, to a given XML file.
	 * Most code was taken from https://examples.javacodegeeks.com/core-java/xml/parsers/documentbuilderfactory/create-xml-file-in-java-using-dom-parser-example/
	 * @param attributes the attributes of an entity to save
	 * @param fileName the name of the file to write to
	 * @throws TransformerFactoryConfigurationError 
	 * @throws TransformerException 
	 */
Writes the data given in a map, to a given XML file.
Writes the data given in a map to a given XML file .
public void writeXML(Map<Class, Object[]> attributes, String fileName) throws TransformerFactoryConfigurationError, TransformerException {
		Document document = DOCUMENT_BUILDER.newDocument();
		Element root = document.createElement(DOCUMENT_TITLE);
		root.setAttribute("name", fileName);
		System.out.println("SAVING TO " + DataUtils.getGame());
		root.setAttribute("game", DataUtils.getGame());
		document.appendChild(root);
		for (Class compClass : attributes.keySet()) {
			String compName = compClass.getName().replace(COMPONENT_PREFIX, "");
			Element comp = document.createElement(compName);
			root.appendChild(comp);
			if (attributes.get(compClass).length == 0) {
				comp.appendChild(document.createTextNode(""));
			} else {
        			for (Object o : attributes.get(compClass)) {
        				comp.appendChild(document.createTextNode(String.valueOf(o)));
        			}
			}
		}
		Transformer t = TransformerFactory.newInstance().newTransformer();
		DOMSource ds = new DOMSource(document);
		StreamResult sr = new StreamResult(new File(FOLDER_PATH + fileName + XML_EXTENSION));
		t.transform(ds, sr);
		System.out.println("XML file created and saved to " + FOLDER_PATH + fileName);
	}
public void writeXML ( Map < Class , Object [ ] > attributes , String fileName ) throws TransformerFactoryConfigurationError , TransformerException { Document document = DOCUMENT_BUILDER . newDocument ( ) ; Element root = document . createElement ( DOCUMENT_TITLE ) ; root . setAttribute ( "name" , fileName ) ; System . out . println ( "SAVING TO " + DataUtils . getGame ( ) ) ; root . setAttribute ( "game" , DataUtils . getGame ( ) ) ; document . appendChild ( root ) ; for ( Class compClass : attributes . keySet ( ) ) { String compName = compClass . getName ( ) . replace ( COMPONENT_PREFIX , "" ) ; Element comp = document . createElement ( compName ) ; root . appendChild ( comp ) ; if ( attributes . get ( compClass ) . length == 0 ) { comp . appendChild ( document . createTextNode ( "" ) ) ; } else { for ( Object o : attributes . get ( compClass ) ) { comp . appendChild ( document . createTextNode ( String . valueOf ( o ) ) ) ; } } } Transformer t = TransformerFactory . newInstance ( ) . newTransformer ( ) ; DOMSource ds = new DOMSource ( document ) ; StreamResult sr = new StreamResult ( new File ( FOLDER_PATH + fileName + XML_EXTENSION ) ) ; t . transform ( ds , sr ) ; System . out . println ( "XML file created and saved to " + FOLDER_PATH + fileName ) ; }
Writes the data given in a map, to a given XML file.
Writes the data given in a map to a given XML file .
// get rid of everything in front of the name itself