@Override
    public void save(Savable object, OutputStream outputStream) throws IOException {
        Document document = null;
        try {
            document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
        } catch (ParserConfigurationException ex) {
            throw new IOException(ex);
        }
        document.setXmlStandalone(true);    // for some reason the transformer output property below doesn't work unless the document is set to standalone

        // Initialize the DOMOutputCapsule when saving, so we don't retain state of previous exports.
        domOut = new DOMOutputCapsule(document, this);

        domOut.write(object, "savable", null);

        DOMSource source = new DOMSource(domOut.getDoc());
        StreamResult result = new StreamResult(outputStream);

        try {
            TransformerFactory tfFactory = TransformerFactory.newInstance();
            tfFactory.setAttribute("indent-number", indentSpaces);

            Transformer transformer = tfFactory.newTransformer();
            transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");

            if (indentSpaces > 0) {
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            }

            transformer.transform(source, result);
        } catch (TransformerException ex) {
            throw new IOException(ex);
        }
    }
Part of the jME XML IO system as introduced in the Google Code jmexml project.

@author Kai Rabien (hevee) - original author of the code.google.com jmexml project
@author Doug Daniels (dougnukem) - adjustments for jME 2.0 and Java 1.5
jme3-plugins/src/xml/java/com/jme3/export/xml/XMLExporter.java