public void save(Writer writer) {
        try {
            if (writer == null) {
                writer = new OutputStreamWriter(System.out);
            }
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            Transformer transformer = transformerFactory.newTransformer();
            DOMSource source = new DOMSource(doc);

            StringWriter sw = new StringWriter();
            StreamResult result = new StreamResult(sw);

            transformer.transform(source, result);

            writer.write(sw.toString());
            writer.flush();
            writer.close();
        } catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) {
        } catch (TransformerException transformerException) {
        } catch (IOException iOException) {
        }
    }