code: public void writeAsMusicXML(Document doc, BufferedWriter writer) throws IOException {
  		/*
  		 * writer.write("<"+node.getNodeName()); NamedNodeMap attr =
  		 * node.getAttributes(); if (attr!=null) for (int i=0;
  		 * i<attr.getLength(); i++) writer.write(" " +
  		 * attr.item(i).getNodeName() + "=" + attr.item(i).getNodeValue());
  		 * writer.write(">"); writer.newLine(); NodeList nlist =
  		 * node.getChildNodes(); for (int i=0; i<nlist.getLength(); i++)
  		 * writeAsMusicXML(writer, nlist.item(i));
  		 * writer.write("</"+node.getNodeName()+">"); writer.newLine();
  		 */
  		try {
  			TransformerFactory transfac = TransformerFactory.newInstance();
  			Transformer trans = transfac.newTransformer();
  			// trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
  			trans.setOutputProperty(OutputKeys.INDENT, "yes");
  			trans.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "-//Recordare//DTD MusicXML 2.0 Partwise//EN");
  			trans.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "http://www.musicxml.org/dtds/partwise.dtd");
  
  			// create string from xml tree
  			// StringWriter sw = new StringWriter();
  			StreamResult result = new StreamResult(writer);
  			DOMSource source = new DOMSource(doc);
  
  			trans.transform(source, result);
  		} catch (Exception e) {
  			e.printStackTrace();
  		}
  		// String xmlString = sw.toString();
  		// }
  	}
docs: Writes the specified Node to the given writer.
  
  @param node
  A DOM node.
  @param writer
  A stream writer.
  @throws IOException
  Thrown if the file cannot be created.